langchain - ✅(Solved) Fix feat(partners): ContextOverflowError for Groq/Mistral + standard test coverage [3 pull requests, 2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#37532Fetched 2026-05-20 03:39:24
View on GitHub
Comments
2
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
cross-referenced ×3commented ×2closed ×1labeled ×1

Error Message

The Feb 2026 changelog notes that SummarizationMiddleware auto-triggers when a chat model raises ContextOverflowError, but today only langchain-anthropic and langchain-openai map provider context-limit errors to that exception.

Fix Action

Fixed

PR fix notes

PR #37529: feat(groq): raise ContextOverflowError on context limit exceeded

Description (problem / solution / changelog)

Fixes #37532


Summary

  • Add GroqContextOverflowError (subclasses groq.BadRequestError and ContextOverflowError)
  • Map context_length_exceeded in _generate, _agenerate, _stream, _astream
  • Override get_num_tokens_from_messages() to count tool schema tokens via tiktoken
  • Unit tests + opt in to raises_on_context_overflow integration tests

Problem

SummarizationMiddleware auto-triggers on ContextOverflowError. Groq raises groq.BadRequestError with context_length_exceeded but never converts it, so summarization does not auto-trigger for Groq users.

AI-assisted contribution.

Changed files

  • libs/partners/groq/langchain_groq/chat_models.py (modified, +88/-8)
  • libs/partners/groq/pyproject.toml (modified, +1/-0)
  • libs/partners/groq/tests/integration_tests/test_standard.py (modified, +4/-0)
  • libs/partners/groq/tests/unit_tests/test_chat_models.py (modified, +150/-0)
  • libs/partners/groq/uv.lock (modified, +185/-1)

PR #37530: feat(mistralai): raise ContextOverflowError on context limit exceeded

Description (problem / solution / changelog)

Fixes #37532


Summary

  • Add MistralContextOverflowError (subclasses httpx.HTTPStatusError and ContextOverflowError)
  • Map context overflow HTTP 400 errors in generate/stream paths
  • Override get_num_tokens_from_messages() to count tool schema tokens via tiktoken
  • Unit tests + opt in to raises_on_context_overflow integration tests

Problem

Mistral context limit errors surface as httpx.HTTPStatusError without conversion to ContextOverflowError, so SummarizationMiddleware does not auto-trigger.

AI-assisted contribution.

Changed files

  • libs/partners/mistralai/langchain_mistralai/chat_models.py (modified, +109/-20)
  • libs/partners/mistralai/pyproject.toml (modified, +1/-0)
  • libs/partners/mistralai/tests/integration_tests/test_standard.py (modified, +4/-0)
  • libs/partners/mistralai/tests/unit_tests/test_chat_models.py (modified, +147/-0)
  • libs/partners/mistralai/uv.lock (modified, +185/-1)

PR #37531: feat(standard-tests): add ContextOverflowError behavior test

Description (problem / solution / changelog)

Fixes #37532


Summary

  • Add raises_on_context_overflow property to ChatModelTests (default False)
  • Add test_context_overflow_raises_correct_error and async variant

Problem

The standard test suite has no coverage for ContextOverflowError behavior. Partners that implement the mapping have no enforcement.

AI-assisted contribution.

Changed files

  • libs/standard-tests/langchain_tests/integration_tests/chat_models.py (modified, +49/-0)
  • libs/standard-tests/langchain_tests/unit_tests/chat_models.py (modified, +11/-0)
RAW_BUFFERClick to expand / collapse

Package

  • langchain-groq
  • langchain-mistralai
  • langchain-tests

Feature Description

The Feb 2026 changelog notes that SummarizationMiddleware auto-triggers when a chat model raises ContextOverflowError, but today only langchain-anthropic and langchain-openai map provider context-limit errors to that exception.

Groq returns groq.BadRequestError with code: context_length_exceeded and Mistral returns HTTP 400 with a context-length message — neither is converted today, so summarization never auto-triggers for those providers.

Additionally, BaseChatModel.get_num_tokens_from_messages() ignores tool schemas (with a warning), which makes token estimates low for tool-heavy agents and can delay summarization.

Proposed Solution

  1. langchain-groq: Add GroqContextOverflowError, map context overflow in _generate/_stream/async variants; override get_num_tokens_from_messages to count tool schemas (tiktoken approximation).
  2. langchain-mistralai: Same pattern using httpx.HTTPStatusError subclass.
  3. langchain-tests: Add opt-in raises_on_context_overflow flag and integration tests.

Motivation

Parity with Anthropic/OpenAI for SummarizationMiddleware and more accurate token budgeting when tools are bound.

Additional Context

Prepared PRs (closed pending issue link + assignee):

AI-assisted contribution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING