High severity intermediate · Fix: 5-10 min

FireworksAIJSONParseError

fireworks_ai.errors.FireworksAIJSONParseError

What this error means
Fireworks AI failed to parse the LLM response as valid JSON in JSON mode due to unexpected formatting or extra characters.

Stack trace

traceback
fireworks_ai.errors.FireworksAIJSONParseError: Failed to parse JSON output from LLM: Expecting value: line 1 column 1 (char 0)
  File "/app/fireworks_ai/parser.py", line 45, in parse_json_mode
    parsed = json.loads(raw_response)  # <-- error here
  File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
QUICK FIX
Add prompt instructions to return only raw JSON without markdown fences and preprocess responses to strip any extra characters before parsing.

Why it happens

Fireworks AI expects the LLM to return a strictly valid JSON string when operating in JSON mode. If the LLM returns extra text, markdown fences, or malformed JSON, the parser raises this error because json.loads() cannot decode the response.

Detection

Log or capture the raw LLM response before parsing and validate it against JSON syntax; catching FireworksAIJSONParseError allows you to inspect malformed outputs before crashing.

Causes & fixes

1

LLM response includes markdown fences or extra explanatory text around JSON

✓ Fix

Modify the prompt to instruct the LLM to return only raw JSON without markdown or extra text, or preprocess the response to strip fences before parsing.

2

LLM output contains trailing commas or invalid JSON syntax

✓ Fix

Use a JSON sanitizer or stricter prompt instructions to ensure the LLM outputs valid JSON without trailing commas or syntax errors.

3

Using a base model that does not reliably follow JSON output instructions

✓ Fix

Switch to a model fine-tuned for structured JSON output or use Fireworks AI’s recommended models that enforce JSON compliance.

Code: broken vs fixed

Broken - triggers the error
python
from fireworks_ai import FireworksAI

client = FireworksAI(api_key="sk-incorrect")
response = client.generate(prompt="Return JSON mode output")
parsed = client.parse_json_mode(response)  # This line raises FireworksAIJSONParseError
print(parsed)
Fixed - works correctly
python
import os
from fireworks_ai import FireworksAI

client = FireworksAI(api_key=os.environ["FIREWORKS_API_KEY"])
prompt = "Return ONLY raw JSON without markdown fences or extra text."
response = client.generate(prompt=prompt)
# Strip markdown fences if present
clean_response = response.strip().strip('`')
parsed = client.parse_json_mode(clean_response)  # Fixed: cleaned input for JSON parsing
print(parsed)
Added prompt instructions to enforce raw JSON output and stripped markdown fences from the response before parsing to avoid JSON decode errors.

Workaround

Catch FireworksAIJSONParseError, extract JSON substring using regex from the raw response, then parse with json.loads() as a fallback to handle malformed outputs.

Prevention

Use strict prompt engineering to enforce JSON-only output and validate responses with schema validators or Fireworks AI’s built-in JSON output modes to avoid parsing errors.

Python 3.9+ · fireworks-ai >=1.0.0 · tested on 1.2.3
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.