Skip to main content
The dottxt Python SDK accepts a wide range of Python types as 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)
The return type follows the input: a Pydantic model class returns a validated model instance, and other supported types return parsed JSON.

Pydantic model

Use a Pydantic model when you want runtime validation alongside generation. The result is a validated model instance.
Python
See Pydantic for the full schema mapping.

TypedDict

Use a TypedDict 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 an Enum 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 like list[...], dict[...], and tuple[...] work directly.
Python

JSON Schema (string or dict)

You can also pass JSON Schema directly as a Python dict 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