Skip to main content
Typed output allows constraining LLM responses to specific JSON schemas.

Basic JSON

You can pass a JSON schema to the outputSchema parameter of the Agent.send method. The schema is used to constrain the LLM’s response to a specific JSON object shape.

Parsed Map

You can also pass a type to the sendFor method. By default, dartantic already knows how to parse the LLM’s response to a Map<String, dynamic>.

Custom Types

If you’d like to parse the JSON output to a custom type, you can pass a type to the sendFor method along with the outputFromJson parameter.

Schema Generation

Hand-writing schemas and JSON serialization is a lot of boilerplate. Consider using the json_serializable package to automate this:

Streaming

You can stream structured JSON from the provider by passing the outputSchema parameter to the sendStream method.
This is useful if you’d like to render the JSON progressively as it’s streamed.

With Tools

Most providers support both tools and typed output in the same request, allowing you to gather information via tools and return structured results:

Provider Support

Google’s Double Agent Pattern: Google’s API doesn’t support tools and typed output in a single call, but dartantic handles this transparently with a two-phase approach: first executing tools, then requesting structured output with the tool results. See the typed output example for working code.

Examples

Next Steps