response_format on generate(...), for many shapes you don’t need to write or generate JSON Schema at all.
Install
Supported response_format types
DotTxt.generate(...) and AsyncDotTxt.generate(...) accept response_format as any of:
- a Pydantic model class
- a TypedDict type
- a dataclass type
- an Enum class
- a
typing.Literal[...]type - a
typing.Union[...]type - a
typing.Optional[...]type - typed containers such as
list[...],dict[...],tuple[...] - a JSON string containing JSON Schema
- a JSON object (
dict)
Pydantic model
Use a Pydantic model when you want runtime validation alongside generation. The result is a validated model instance.Python
TypedDict
Use aTypedDict for a lightweight class declaration without Pydantic as a dependency. The result is a plain dict.
Python
Dataclass
Standard library@dataclass types are supported as well.
Python
Enum and Literal
Pass anEnum class or a typing.Literal[...] when the entire output is a single value drawn from a fixed set.
Python
Union and Optional
typing.Union[...] and typing.Optional[...] constrain the output to one of several types.
Python
Typed containers
Typed containers likelist[...], dict[...], and tuple[...] work directly.
Python
JSON Schema (string or dict)
You can also pass JSON Schema directly as a Pythondict or as a JSON string. This is useful when you have a schema authored elsewhere — by hand, by Quicktype, by Genson, or shared from another service.
Python