InputData#

API Reference > Modeling > InputData

The decision_ai.InputData class is the base class for defining the input data structure of your optimization problem.

Purpose:

  • Define the data schema for your optimization model

  • Ensure type safety and validation using Pydantic

  • Provide clear documentation of expected input format

  • Enable automatic data validation and parsing

  • Support serialization and deserialization for client-server communication

Usage Example#

from decision_ai import InputData
from pydantic import Field
from typing import Dict, List

class StaffSchedulingInputData(InputData):
    # Basic parameters
    num_days: int = Field(description="Number of days to schedule")
    num_shifts: int = Field(description="Number of shifts per day")

    # Employee data
    employees: List[str] = Field(description="List of employee names")
    employee_skills: Dict[str, List[str]] = Field(
        description="Skills for each employee"
    )

    # Demand data
    demand: Dict[str, Dict[str, int]] = Field(
        description="Demand for each skill per day/shift"
    )

    # Constraints
    max_hours_per_week: int = Field(
        default=40,
        description="Maximum hours per employee per week"
    )

# Usage
input_data = StaffSchedulingInputData(
    num_days=7,
    num_shifts=3,
    employees=["Alice", "Bob", "Charlie"],
    employee_skills={
        "Alice": ["nursing", "admin"],
        "Bob": ["nursing"],
        "Charlie": ["admin", "cleaning"]
    },
    demand={
        "Monday": {"nursing": 2, "admin": 1},
        "Tuesday": {"nursing": 3, "admin": 1},
        # ... more days
    }
)

Class Reference#

class decision_ai.InputData#

Bases: BaseModel

Base class for defining input data structures for optimization problems.

This class inherits from Pydantic’s BaseModel, providing automatic validation, serialization, and deserialization of input data. All standard Pydantic features are supported.

Note: arbitrary_types_allowed is disabled to ensure proper serialization.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': False}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

Best Practices#

  1. Use Descriptive Field Names - Make your data structure self-explanatory

  2. Add Field Descriptions - Help users understand what each field represents

  3. Set Reasonable Defaults - Where appropriate, provide sensible default values

  4. Use Type Hints - Leverage Python’s type system for better validation

  5. Group Related Data - Organize complex data into logical nested structures

  6. Ensure Serializability - All field types must support model_dump() and model_validate() for proper client-server communication

  7. Use InputData for Nested Models - Any nested Pydantic models should inherit from InputData rather than BaseModel for consistency