schema_to_dict()
Convert a Pydantic model class to a JSON Schema dictionary.
Usage
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
BaseModelsubclass.
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"]