Skip to content

Fall back to the schema in the prompt when Anthropic can't compile it - #30

Closed
Jchinonso wants to merge 1 commit into
AienTech:mainfrom
Jchinonso:fix/anthropic-grammar-too-large
Closed

Jchinonso wants to merge 1 commit into
AienTech:mainfrom
Jchinonso:fix/anthropic-grammar-too-large

Conversation

@Jchinonso

@Jchinonso Jchinonso commented Oct 29, 2026 •

Copy link
Copy Markdown

Fixes #24.

The profile import's extracted_profile schema has 32 nullable fields, more than Anthropic's structured outputs can compile. The Messages API answers with 400 invalid_request_error: The compiled grammar is too large…, which Dossier shows as "The AI provider ran into a problem", so importing a resume with Anthropic always fails.

Change (src/lib/ai/providers/anthropic.ts): on that 400, and only that one, send the request once more without output_config.format, with the schema spelled out in the system prompt through withJsonSchema. The answer is still validated against the schema by BaseProvider, as before. Every other 400 fails as it did.

Tests (src/lib/ai/providers.test.ts):

  • the grammar 400 is retried without output_config, with the schema in the system prompt, and the answer parses;
  • any other 400 isn't retried.

yarn vitest run src/lib/ai/providers.test.ts: 44 passed. Lint and type-check are clean. Tried by hand with Dossier 1.9.2 built from source and claude-sonnet-5: importing a PDF resume failed before and works with this change.

The profile import's schema has 32 nullable fields, more than Anthropic's
structured outputs can compile. The Messages API answers with a 400
("The compiled grammar is too large"), which Dossier shows as "The AI
provider ran into a problem", so importing a resume with Anthropic always
failed.

On that 400, send the request again without output_config.format, with
the schema spelled out in the system prompt (withJsonSchema). The answer
is still validated against the schema as before. Other 400s fail as they
did.

Fixes AienTech#24

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AienTech

Copy link
Copy Markdown
Owner

Thanks for this, @Jchinonso, and for trying it by hand! The same fix came in with #16. It matches the "too complex" refusals by their wording, so other 400s still fail fast, and it remembers the fallback per model and schema. It's out in 1.10.0, so I'm closing this one.

@AienTech AienTech closed this Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resume import fails with Anthropic: “compiled grammar is too large”

2 participants