Troubleshooting structured output generation

Last updated: September 12, 2025

When working with structured outputs, you may encounter issues where your generated JSON gets cut off or contains errors. Here are the key considerations and solutions:

1. Token Limits

Check the maximum token limit of your model and make sure you are under that. You can find current model specifications in our serverless models documentation.

2. Malformed JSON

Double check your example JSON is correct. The language model will follow your example exactly, including any syntax errors. Always validate your example JSON before using it in prompts.

Common symptoms include:

  • Unterminated string errors

  • Repeated newline characters (\n\n\n)

  • Incomplete JSON structures

  • FinishReason showing 'stop' when output appears truncated