Skip to content

Capabilities

Structured Outputs

JSON mode, JSON schema enforcement, typed responses

Read this when
  • Forcing the model to return JSON / a specific schema
  • Implementing GenerateObject for a new provider

pi-go exposes structured output through the optional ObjectProvider interface. The generic helper ai.GenerateObject[T] takes a bound LanguageModel and returns a typed Go value; catalog.GenerateObject[T] and pi.GenerateObject[T] offer the same spec-first form as GenerateText.

Compatibility

ProviderAPIpi-goNotes
Anthropic✅ JSON mode + native schema⚠️implemented via synthetic-tool trick — defines a tool from the schema and forces tool call (anthropic.go:407-523)
OpenAI Chatresponse_format: json_schema with strict: true⚠️implemented via JSON object mode (response_format: json_object); the derived schema is not sent, so output is valid JSON but not schema-constrained (openai.go:414)
OpenAI Responsestext.format: json_schema strictnot implemented
Google GeminiresponseSchema (subset of JSON Schema)native responseSchema via ResponseJsonSchema (google.go:700)
Claude CLI--json-schema flag(claude.go:194-250)
Codex CLI--output-schema flagwrites the JSON Schema to a temp file and passes it to codex exec --output-schema (codex.go)

Provider Documentation

pi-go Gaps

  • OpenAI Chat uses plain json_object mode without sending the schema; strict native json_schema is not wired. OpenAI Responses structured output is unimplemented.
  • Anthropic synthetic-tool path works but bypasses native JSON support — emits an extra tool round-trip and forfeits any model-specific JSON-mode optimizations.
  • OutputSchema on ai.ToolInfo is defined but unused — could drive native structured output for tool results.