High severity intermediate · Fix: 5-10 min

InstructorMaxRetriesExceededParseError

instructor.errors.InstructorMaxRetriesExceededParseError

What this error means
The instructor library failed to parse the LLM output correctly after the maximum number of retry attempts was exceeded.

Stack trace

traceback
instructor.errors.InstructorMaxRetriesExceededParseError: Maximum retries exceeded while attempting to parse LLM output
  File "/usr/local/lib/python3.9/site-packages/instructor/parser.py", line 142, in parse_with_retries
    raise InstructorMaxRetriesExceededParseError("Max retries exceeded parse error")
  File "/usr/local/lib/python3.9/site-packages/instructor/parser.py", line 120, in parse
    parsed = self._parse_raw_output(raw_output)
  File "/usr/local/lib/python3.9/site-packages/instructor/parser.py", line 85, in _parse_raw_output
    raise ParseError("Failed to parse output")
QUICK FIX
Add explicit instructions in your prompt to return raw JSON without markdown fences and increase max_retries if needed.

Why it happens

The instructor library expects the LLM output to conform to a strict format for parsing. If the output deviates due to markdown fences, unexpected text, or format inconsistencies, the parser retries. When all retry attempts fail, this error is raised indicating persistent parse failure.

Detection

Monitor parse attempts and catch InstructorMaxRetriesExceededParseError exceptions; log raw LLM outputs on failure to identify format mismatches before the retries are exhausted.

Causes & fixes

1

LLM output includes markdown fences or extra formatting around the expected JSON or structured data

✓ Fix

Modify the prompt to instruct the LLM to return raw JSON without markdown fences or use a parser that automatically strips markdown fences.

2

The prompt or schema expects fields that do not match the actual LLM output keys or structure

✓ Fix

Ensure the prompt instructions and the parsing schema are aligned exactly with the expected field names and output format.

3

Using a base LLM model that does not reliably follow output format instructions, causing inconsistent responses

✓ Fix

Switch to an instruction-tuned model known to follow output format instructions, such as gpt-4o-mini or claude-3-5-haiku-20241022.

Code: broken vs fixed

Broken - triggers the error
python
from instructor import Instructor

instructor = Instructor(max_retries=3)
response = instructor.parse(raw_llm_output)  # This line raises InstructorMaxRetriesExceededParseError
Fixed - works correctly
python
import os
from instructor import Instructor

instructor = Instructor(max_retries=3)
# Added prompt instruction to avoid markdown fences and ensure raw JSON output
prompt = "Return ONLY raw JSON without markdown fences."
raw_llm_output = get_llm_output_with_prompt(prompt)  # hypothetical function
response = instructor.parse(raw_llm_output)  # Fixed: output matches expected format
print(response)
Added prompt instructions to ensure the LLM returns raw JSON without markdown fences, preventing parse failures and retry exhaustion.

Workaround

Catch InstructorMaxRetriesExceededParseError, extract JSON manually from the raw LLM output using regex to remove markdown fences, then parse with json.loads() as a fallback.

Prevention

Use structured output features of the LLM API or instruction-tuned models that guarantee schema-valid responses, eliminating parser fragility and retry exhaustion.

Python 3.9+ · instructor >=1.0.0 · tested on 1.2.0
Verified 2026-04
Verify ↗

Community Notes

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