Understanding Output Modes
Polyglot supports multiple output modes through theMode enum:
- How the request is formatted and sent to the provider
- How the provider’s response is processed
- What extraction or validation is applied to the response
Output Modes Overview
| Mode | Description | Best For |
|---|---|---|
OutputMode::Text | Default mode, returns unstructured text | Simple text generation |
OutputMode::Json | Returns structured JSON data | Structured data processing |
OutputMode::JsonSchema | Returns JSON data validated against a schema | Strictly typed data |
OutputMode::MdJson | Returns JSON wrapped in Markdown code blocks | Compatibility across providers |
OutputMode::Tools | Returns function/tool calls | Function calling/external actions |
Choosing the Right Format
Consider these factors when selecting an output format:- Complexity of the data: More complex data structures benefit from JSON Schema
- Provider support: Check which formats are natively supported by your provider
- Consistency requirements: Stricter format requirements favor JSON Schema or Tools
- Application needs: Consider how the data will be used in your application
Improving Format Reliability
For better results:- Be explicit in prompts: Clearly describe the expected format
- Provide examples: Show what good responses look like
- Use constraints: Specify limits and requirements
- Test across providers: Verify formats work with all providers you use
- Implement fallbacks: Have backup strategies for format failures