Skip to content

Only map Mistral 3051 to ModelContextWindowExceededError on context length overflow - #12864

Closed
princejain756 wants to merge 1 commit into
pydantic:mainfrom
princejain756:fix/mistral-3051-context-window
Closed

princejain756 wants to merge 1 commit into
pydantic:mainfrom
princejain756:fix/mistral-3051-context-window

Conversation

@princejain756

@princejain756 princejain756 commented Nov 8, 2026 •

Copy link
Copy Markdown

Fixes #12861

Mistral returns code 3051 for generic invalid-request errors too (like an invalid tool name), not only when the prompt overflows the context window. Matching 3051 unconditionally meant every 400 with code 3051 raised ModelContextWindowExceededError instead of ModelHTTPError.

Scoped the 3051 check in mistral.py so it only maps to ModelContextWindowExceededError when the message mentions maximum context length (same pattern xai.py uses for gRPC INVALID_ARGUMENT), and added a test in tests/models/test_error_categories.py.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for your interest in this issue! To avoid duplicate effort, please wait to be assigned before opening a PR.

This PR has been closed automatically because issue #12861 is not assigned to you. If you believe this was closed in error, please comment on the issue and a maintainer can reassess.

@github-actions github-actions Bot closed this Nov 8, 2026
@github-actions github-actions Bot added size: S Small PR (≤100 weighted lines) bug Report that something isn't working, or PR implementing a fix labels Nov 8, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at b5fe837

Macroscope's review found this PR approvable — Mistral error 3051 now maps to context-window overflow only when the message identifies that condition; other invalid arguments retain standard HTTP error categorization. The narrowly scoped change includes regression coverage and does not alter successful requests or stored data.

You can add or adjust custom eligibility rules. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Report that something isn't working, or PR implementing a fix size: S Small PR (≤100 weighted lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mistral: error code 3051 is always raised as ModelContextWindowExceededError, also for invalid arguments

1 participant