Skip to content

typedefs

Class info

Classes

Name Children Inherits
ArrayProperty
schemez.functionschema.typedefs
Schema property for array types.
    ObjectProperty
    schemez.functionschema.typedefs
    Schema property for nested object types.
      OpenAIFunctionDefinition
      schemez.functionschema.typedefs
      Schema for the function definition part of an OpenAI tool.
        OpenAIFunctionTool
        schemez.functionschema.typedefs
        Complete OpenAI tool definition for function calling.
          PropertyBase
          schemez.functionschema.typedefs
          Base schema property with common fields.
            SimpleProperty
            schemez.functionschema.typedefs
            Schema property for primitive types.
              ToolParameters
              schemez.functionschema.typedefs

                🛈 DocStrings

                ToolParameters module-attribute

                ToolParameters = TypedDict(
                    "ToolParameters",
                    {
                        "type": Literal["object"],
                        "properties": dict[str, Any],
                        "required": NotRequired[list[str]],
                        "$defs": NotRequired[dict[str, Any]],
                    },
                )
                

                Schema for tool parameters (JSON Schema object type).

                ArrayProperty

                Bases: PropertyBase

                Schema property for array types.

                Source code in src/schemez/functionschema/typedefs.py
                class ArrayProperty(PropertyBase):
                    """Schema property for array types."""
                
                    type: Literal["array"]
                    items: Property
                

                ObjectProperty

                Bases: PropertyBase

                Schema property for nested object types.

                Source code in src/schemez/functionschema/typedefs.py
                class ObjectProperty(PropertyBase):
                    """Schema property for nested object types."""
                
                    type: Literal["object"]
                    properties: NotRequired[dict[str, Property]]
                    required: NotRequired[list[str]]
                    additionalProperties: NotRequired[bool]
                

                OpenAIFunctionDefinition

                Bases: TypedDict

                Schema for the function definition part of an OpenAI tool.

                This represents the inner "function" object that contains the actual function metadata and parameters.

                Source code in src/schemez/functionschema/typedefs.py
                class OpenAIFunctionDefinition(TypedDict):
                    """Schema for the function definition part of an OpenAI tool.
                
                    This represents the inner "function" object that contains the actual
                    function metadata and parameters.
                    """
                
                    name: str
                    description: str
                    parameters: ToolParameters
                

                OpenAIFunctionTool

                Bases: TypedDict

                Complete OpenAI tool definition for function calling.

                This represents the top-level tool object that wraps a function definition and identifies it as a function tool type.

                Source code in src/schemez/functionschema/typedefs.py
                class OpenAIFunctionTool(TypedDict):
                    """Complete OpenAI tool definition for function calling.
                
                    This represents the top-level tool object that wraps a function definition
                    and identifies it as a function tool type.
                    """
                
                    type: Literal["function"]
                    function: OpenAIFunctionDefinition
                

                PropertyBase

                Bases: TypedDict

                Base schema property with common fields.

                Source code in src/schemez/functionschema/typedefs.py
                class PropertyBase(TypedDict, total=False):
                    """Base schema property with common fields."""
                
                    description: str
                    format: str
                    default: Any
                

                SimpleProperty

                Bases: PropertyBase

                Schema property for primitive types.

                Source code in src/schemez/functionschema/typedefs.py
                class SimpleProperty(PropertyBase):
                    """Schema property for primitive types."""
                
                    type: Literal["string", "number", "integer", "boolean"]
                    enum: NotRequired[list[Any]]
                

                clean_property

                clean_property(prop: dict[str, Any], description: str | None = None) -> Property
                

                Convert complex schema properties to simple OpenAI-compatible types.

                Parameters:

                Name Type Description Default
                prop dict[str, Any]

                Complex property definition

                required
                description str | None

                Optional property description

                None

                Returns:

                Type Description
                Property

                Simplified Property compatible with OpenAI

                Source code in src/schemez/functionschema/typedefs.py
                def clean_property(
                    prop: dict[str, Any],
                    description: str | None = None,
                ) -> Property:
                    """Convert complex schema properties to simple OpenAI-compatible types.
                
                    Args:
                        prop: Complex property definition
                        description: Optional property description
                
                    Returns:
                        Simplified Property compatible with OpenAI
                    """
                    if "anyOf" in prop or "oneOf" in prop:
                        types = []
                        for subschema in prop.get("anyOf", prop.get("oneOf", [])):
                            if isinstance(subschema, dict):
                                types.append(subschema.get("type"))  # noqa: PERF401
                
                        # If null is allowed, treat as optional string
                        if "null" in types:
                            return _create_simple_property(
                                type_str="string",
                                description=description or prop.get("description"),
                                default=None,
                            )
                
                        # Get first non-null type or default to string
                        first_type = next((t for t in types if t != "null"), "string")
                        if first_type not in {"string", "number", "integer", "boolean"}:
                            first_type = "string"
                
                        return _create_simple_property(
                            type_str=first_type,  # Valid since we checked above
                            description=description or prop.get("description"),
                            default=prop.get("default"),
                        )
                
                    if prop.get("type") == "array":
                        items = prop.get("items", {"type": "string"})
                        if isinstance(items, dict):
                            items = clean_property(items)
                        return _create_array_property(
                            items=items,
                            description=description or prop.get("description"),
                        )
                
                    if prop.get("type") == "object":
                        sub_props = prop.get("properties", {})
                        cleaned_props = {name: clean_property(p) for name, p in sub_props.items()}
                        return _create_object_property(
                            description=description or prop.get("description"),
                            properties=cleaned_props,
                            required=prop.get("required"),
                        )
                
                    type_str = prop.get("type", "string")
                    if type_str not in {"string", "number", "integer", "boolean"}:
                        type_str = "string"
                
                    return _create_simple_property(
                        type_str=type_str,
                        description=description or prop.get("description"),
                        enum_values=prop.get("enum"),
                        default=prop.get("default"),
                        fmt=prop.get("format"),
                    )