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
| Provider | API | pi-go | Notes |
|---|---|---|---|
| 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 Chat | ✅ response_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 Responses | ✅ text.format: json_schema strict | ❌ | not implemented |
| Google Gemini | ✅ responseSchema (subset of JSON Schema) | ✅ | native responseSchema via ResponseJsonSchema (google.go:700) |
| Claude CLI | ✅ --json-schema flag | ✅ | (claude.go:194-250) |
| Codex CLI | ✅ --output-schema flag | ✅ | writes 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_objectmode without sending the schema; strict nativejson_schemais 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.
OutputSchemaonai.ToolInfois defined but unused — could drive native structured output for tool results.