schema_to_dict()

Convert a Pydantic model class to a JSON Schema dictionary.

Usage

Source

schema_to_dict(data_model)

Useful for inspecting what schema will be sent to the LLM, logging, or building dynamic schemas.

Parameters

data_model: type
A Pydantic BaseModel subclass.

Returns

dict[str, Any]
The JSON Schema representation of the model.

Examples

from pydantic import BaseModel
import talk_box as tb

class Weather(BaseModel):
    city: str
    temp_f: float
    condition: str

schema = tb.schema_to_dict(Weather)
schema["properties"]  # {"city": {...}, "temp_f": {...}, "condition": {...}}
schema["required"]    # ["city", "temp_f", "condition"]