Skip to content

Strict Schema

ensure_strict_json_schema

ensure_strict_json_schema(
    schema: dict[str, Any],
    *,
    _reject_open_objects: bool = False,
) -> dict[str, Any]

Mutates the given JSON schema to ensure it conforms to the strict standard that the OpenAI API expects.

Source code in src/agents/strict_schema.py
def ensure_strict_json_schema(
    schema: dict[str, Any],
    *,
    _reject_open_objects: bool = False,
) -> dict[str, Any]:
    """Mutates the given JSON schema to ensure it conforms to the `strict` standard
    that the OpenAI API expects.
    """
    _validate_json_schema_depth(schema)
    if schema == {}:
        return copy.deepcopy(_EMPTY_SCHEMA)
    budget = _NodeBudget(_MAX_SCHEMA_NODES, reject_open_objects=_reject_open_objects)
    return _ensure_strict_root(
        _ensure_strict_json_schema(
            schema,
            path=(),
            root=schema,
            budget=budget,
        )
    )