Skip to main content
Pass a pydantic model as response_format to get JSON that matches it:

How it works

  • A pydantic class becomes a strict json_schema response format.
  • A dict is sent as given, so you can pass {"type": "json_object"} or your own json_schema block.
  • The JSON arrives as the message content string. Parse it yourself, as above.
  • For Claude, RouteHub enforces the schema through a forced tool call, or native structured output on Claude 5.1 and later, and still returns the result as the message content.
The same code works on every provider that supports structured output:
routehub.supports_response_schema(model) tells you whether the catalog lists structured-output support for a model. See Model catalog.