How Response Shaping Works
Polyglot 2.0 does not use output mode enums. Instead, response shape is controlled by the same request fields that providers already expect:- Plain text — the default behavior when no format is specified
- JSON object — set
responseFormatwith typejson_object - JSON schema — set
responseFormatwith typejson_schemaand a schema definition - Tool calls — provide
toolsandtoolChoicedefinitions
Response Shapes at a Glance
Choosing the Right Shape
Consider these factors when selecting a response shape:- Data complexity. More complex or nested data structures benefit from JSON Schema, which enforces the exact shape you need.
- Provider support. Not every provider supports every shape natively. JSON object mode is widely supported; JSON Schema is currently best supported by OpenAI. Check your provider’s capabilities before relying on a specific format.
- Consistency requirements. When you need guaranteed structure across many requests, prefer JSON Schema or tool calls over plain JSON object mode.
- Application needs. If the response will be parsed by downstream code, structured formats save you from fragile string parsing.
Convenience Accessors
Polyglot provides several shortcut methods on theInference facade for reading responses in different formats:
Tips for Reliable Structured Output
For best results when requesting structured responses:- Be explicit in prompts. Clearly describe the expected format, including field names and types.
- Provide examples. Show what a correct response looks like directly in your prompt.
- Use constraints. Specify limits, required fields, and allowed values.
- Test across providers. If your application supports multiple providers, verify that your chosen format works with each one.
- Implement fallbacks. Have backup strategies for when a provider does not support your preferred format natively.