Skip to content

feat(core): add standard model exception types - #39538

Merged
ccurme (ccurme) merged 10 commits into
masterfrom
ccurme/openai/model-error-hierarchy
Aug 19, 2026
Merged

ccurme (ccurme) merged 10 commits into
masterfrom
ccurme/openai/model-error-hierarchy

Conversation

@ccurme

@ccurme ccurme (ccurme) commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Introduces standard exception types in langchain-core for common model failures: authentication, invalid request, rate limit, timeout, etc.

Integration packages raise subclasses that inherit from both the provider SDK's own exception type and the LangChain one, so callers catching exceptions keep working.

from langchain.chat_models import init_chat_model
from langchain_core.exceptions import ModelTimeoutError

model = init_chat_model("openai:gpt-5.6-luna", timeout=0.0001)

try:
    response = model.invoke("Hello")
except ModelTimeoutError:
    print("caught")

Each type also carries is_retryable, which retry middleware now respects (e.g., errors from a bad API key are not retried, while rate limits or server errors are retried as before).

from langchain.chat_models import init_chat_model
from langchain_core.exceptions import ModelError

model = init_chat_model("openai:gpt-5.6-luna", timeout=0.0001)

try:
    response = model.invoke("Hello")
except ModelError as e:
    print(e.is_retryable)

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
@github-actions github-actions Bot added core `langchain-core` package issues & PRs feature For PRs that implement a new feature; NOT A FEATURE REQUEST integration PR made that is related to a provider partner package integration internal langchain `langchain` package issues & PRs openai `langchain-openai` package issues & PRs size: S 50-199 LOC labels Aug 10, 2026
@codspeed

codspeed Bot commented Aug 10, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 17 untouched benchmarks


Comparing ccurme/openai/model-error-hierarchy (ebcde0b) with master (04ae744)

Open in CodSpeed

@github-actions github-actions Bot added anthropic `langchain-anthropic` package issues & PRs fireworks `langchain-fireworks` package issues & PRs mistralai `langchain-mistralai` package issues & PRs size: M 200-499 LOC and removed size: S 50-199 LOC labels Aug 18, 2026
Comment thread libs/core/langchain_core/exceptions.py Resolved
@github-actions github-actions Bot added size: L 500-999 LOC and removed size: M 200-499 LOC labels Aug 19, 2026
# Conflicts:
#	libs/langchain_v1/langchain/agents/middleware/model_retry.py
@ccurme
ccurme (ccurme) marked this pull request as ready for review August 19, 2026 14:28

@robin-agent robin-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open SWE Review found 2 potential issues.

Open in Web • View Open SWE trace

Comment thread libs/core/langchain_core/exceptions.py Resolved
@ccurme ccurme (ccurme) changed the title feat(openai): add ModelError retry classification feat(openai): add standard model exception types Aug 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

anthropic `langchain-anthropic` package issues & PRs core `langchain-core` package issues & PRs feature For PRs that implement a new feature; NOT A FEATURE REQUEST fireworks `langchain-fireworks` package issues & PRs integration PR made that is related to a provider partner package integration internal langchain `langchain` package issues & PRs mistralai `langchain-mistralai` package issues & PRs openai `langchain-openai` package issues & PRs size: L 500-999 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants