Structured outputs ensure model responses conform to your specified format, making them easy to parse and integrate into your application. Fireworks supports two methods: JSON mode (using JSON schemas) and Grammar mode (using custom BNF grammars).Documentation Index
Fetch the complete documentation index at: https://fireworks.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
New to structured outputs? Check out the Serverless Quickstart for a quick introduction.
Quick Start
Force model output to conform to a JSON schema: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)
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 2020-12 constructs, and also accepts Draft-7 keyword aliases (definitions) for backward compatibility:
Supported:
- Types:
string,number,integer,boolean,object,array,null - Object constraints:
properties,required,additionalProperties - Array constraints:
items - Composition:
anyOf,allOf - Reuse:
$defs(Draft 2020-12) anddefinitions(Draft 7), referenced via$ref - Annotations:
$id,$schema,description,title,default - Recursive references (self-recursive
$ref, mutually recursive$defs)
oneOfcomposition- Length/size constraints (
minLength,maxLength,minItems,maxItems) - Regular expressions (
pattern) - External
$refURIs (HTTP/file). Only in-document JSON Pointer fragments are resolved.
JSON Pointer references ($ref)
$ref follows the RFC 6901 JSON Pointer syntax used by JSON Schema 2020-12. Fireworks supports two pointer forms in the same document:
-
Fully-qualified pointer (strict-spec). A
$refwhose fragment is a complete JSON Pointer to the definition’s actual location, e.g.#/properties/A/$defs/Foo. Always resolves to that exact location, regardless of any other definitions in the document. This is fully portable across any conformant JSON Schema 2020-12 implementation. -
Bare shorthand
#/$defs/Foo(Fireworks extension). WhenFoois placed inside a nested subschema (e.g.properties.A.$defs.Foo) instead of at the document root, Fireworks lifts every nested$defs/definitionsentry into a root pool so that the bare pointer resolves. Most converters (OpenAPI, Instructor, LangChainTypeAdapter, pydantic v2) emit this shape, so the shorthand keeps them working without rewrites. This shorthand is not portable — strict validators will returnPointerToNowherefor the same pointer.
- Root-level
$defs[Foo]always wins. IfFooexists at both the document root and a nested location,#/$defs/Fooresolves to the root entry. The fully-qualified pointer to the nested entry continues to work and addresses the nested definition. - Nested vs. nested: if
Fooappears at multiple nested locations and there is no root entry, the first occurrence in document order wins (and the server logs a warning). If you need both, give them distinct names or hoist the shared definition to the root. $defsanddefinitionsare independent pools —#/$defs/Fooand#/definitions/Fooaddress two different schemas, exactly as the spec defines.
Example: recursive schema (linked list)
Example: recursive schema (linked list)
Self-recursive and mutually recursive schemas are supported. The example below is the canonical linked-list shape and works in both
response_format and tool calling parameters:Example: pydantic v2 schemas with `$id`
Example: pydantic v2 schemas with `$id`
Schemas emitted by
pydantic.BaseModel.model_json_schema() typically carry a root $id annotation. This is treated as an identity annotation only — Fireworks never attempts to fetch the URI — and #/$defs/... references resolve correctly within the document:Advanced: Reasoning Model JSON Mode
Advanced: Reasoning Model JSON Mode
Some models support generating structured JSON outputs alongside their reasoning process. The Fireworks Python SDK exposes the model’s reasoning via the
reasoning_content field, keeping it separate from the JSON output in the content field.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
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