New to structured outputs? Check out the Serverless Quickstart for a quick introduction.
Quick Start
Force model output to conform to a JSON schema:Include the schema in both your prompt and the
response_format for best results. The model doesn’t automatically “see” the schema—it’s enforced during generation.Response Format Options
Fireworks supports two JSON mode variants:json_object– Force any valid JSON output (no specific schema)json_schema– Enforce a specific JSON schema (recommended)
Always instruct the model to produce JSON in your prompt. Without this, the model may generate whitespace indefinitely until hitting token limits.
Using arbitrary JSON mode
Using arbitrary JSON mode
Important notes and limitations
Important notes and limitations
Token limits: If
finish_reason="length", the response may be truncated and invalid JSON. Increase max_tokens if needed.Completions API: JSON mode works with both Chat Completions and Completions APIs.Function calling: When using Tool Calling, JSON mode is enabled automatically—these guidelines don’t apply.JSON Schema Support
Fireworks supports most JSON schema specification constructs: Supported:- Types:
string,number,integer,boolean,object,array,null - Object constraints:
properties,required - Array constraints:
items - Nested schemas:
anyOf,$ref
oneOfcomposition- Length/size constraints (
minLength,maxLength,minItems,maxItems) - Regular expressions (
pattern)
Fireworks automatically prevents hallucinated fields by treating schemas with
properties as if "unevaluatedProperties": false is set.Advanced: Reasoning Model JSON Mode
Advanced: Reasoning Model JSON Mode
Some models support generating structured JSON outputs with visible reasoning. In this mode, the model’s response includes a
<think>...</think> section showing its reasoning process, followed by the JSON output.Example Usage
Use Cases
Reasoning mode is useful for:- Debugging: Understanding why the model generated specific outputs
- Auditing: Documenting the decision-making process
- Complex tasks: Scenarios where the reasoning is as valuable as the final answer
Additional Examples
Grammar Mode
For advanced use cases where JSON isn’t sufficient, use Grammar mode to constrain outputs using custom BNF grammars. Grammar mode is ideal for:- Classification tasks – Limit output to a predefined list of options
- Language-specific output – Force output in specific languages or character sets
- Custom formats – Define arbitrary output structures beyond JSON