Skip to content

feat(langchain): Broaden AI provider detection beyond OpenAI and Anthropic#5707

Open
ericapisani wants to merge 3 commits intomasterfrom
ep/broaden-langgraph-model-support-6d0
Open

feat(langchain): Broaden AI provider detection beyond OpenAI and Anthropic#5707
ericapisani wants to merge 3 commits intomasterfrom
ep/broaden-langgraph-model-support-6d0

Conversation

@ericapisani
Copy link
Member

@ericapisani ericapisani commented Mar 19, 2026

Summary

  • Extracts a _get_ai_system() helper that generically detects AI providers from LangChain's _type field, replacing hardcoded "anthropic" / "openai" checks.
  • Adds support for Cohere, Ollama, Mistral, Fireworks, HuggingFace, Groq, NVIDIA, xAI, DeepSeek, Google, and any future LangChain providers without code changes.

Test plan

  • Parametrized test with coverage for real LangChain _llm_type values from various providers
  • CI passes

🤖 Generated with Claude Code

…ropic

Extract _get_ai_system() to generically detect AI providers from LangChain's
_type field instead of hardcoding only "anthropic" and "openai". The function
splits on "-" and skips non-provider segments (cloud prefixes like "azure" and
descriptors like "chat"/"llm") to return the actual provider name.

This adds support for Cohere, Ollama, Mistral, Fireworks, HuggingFace, Groq,
NVIDIA, xAI, DeepSeek, Google, and any future LangChain providers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ericapisani ericapisani requested a review from a team as a code owner March 19, 2026 12:07
@ericapisani ericapisani marked this pull request as draft March 19, 2026 12:07
@ericapisani
Copy link
Member Author

@cursoragent please review this

@cursor
Copy link

cursor bot commented Mar 19, 2026

Please finish setting up background agents. Go to Cursor

@github-actions
Copy link
Contributor

github-actions bot commented Mar 19, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 8.60s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 14382 uncovered lines.

Files with missing lines (1)
File Patch % Lines
langchain.py 3.27% ⚠️ 591 Missing

Generated by Codecov Action

@github-actions
Copy link
Contributor

Codecov Results 📊

9 passed | ⏭️ 1 skipped | Total: 10 | Pass Rate: 90% | Execution Time: 3.63s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 14771 uncovered lines.

Files with missing lines (1)
File Patch % Lines
langchain.py 3.24% ⚠️ 598 Missing

Generated by Codecov Action

@ericapisani
Copy link
Member Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

…s-is

Remove string splitting and filtering logic from _get_ai_system. The
function now returns the LangChain _type value directly without
attempting to extract a provider name from it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 20, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (asgi) Add option to disable suppressing chained exceptions by alexander-alderman-webb in #5714
  • (langchain) Broaden AI provider detection beyond OpenAI and Anthropic by ericapisani in #5707
  • (logging) Separate ignore lists for events/breadcrumbs and sentry logs by sl0thentr0py in #5698

Bug Fixes 🐛

Anthropic

  • Set exception info on streaming span when applicable by alexander-alderman-webb in #5683
  • Patch AsyncStream.close() and AsyncMessageStream.close() to finish spans by alexander-alderman-webb in #5675
  • Patch Stream.close() and MessageStream.close() to finish spans by alexander-alderman-webb in #5674

Other

  • (starlette) Catch Jinja2Templates ImportError by alexander-alderman-webb in #5741

Documentation 📚

  • Add note on AI PRs to CONTRIBUTING.md by sentrivana in #5696

Internal Changes 🔧

  • Pin GitHub Actions to full-length commit SHAs by joshuarli in #5781
  • Add -latest alias for each integration test suite by sentrivana in #5706
  • Use date-based branch names for toxgen PRs by sentrivana in #5704
  • 🤖 Update test matrix with new releases (03/19) by github-actions in #5703
  • Add client report tests for span streaming by sentrivana in #5677

Other

  • Update CHANGELOG.md by sentrivana in #5685

🤖 This preview updates automatically when you update the PR.

@ericapisani ericapisani marked this pull request as ready for review March 20, 2026 10:26
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Raw _type values break gen_ai.system consistency with other integrations
    • Restored normalization of LangChain _type values to return 'openai' and 'anthropic' instead of raw values like 'openai-chat' and 'anthropic-chat', matching the dedicated integrations and maintaining backward compatibility.

Create PR

Or push these changes by commenting:

@cursor push 98e51d01de
Preview (98e51d01de)
diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py
--- a/sentry_sdk/integrations/langchain.py
+++ b/sentry_sdk/integrations/langchain.py
@@ -114,6 +114,11 @@
     if not ai_type or not isinstance(ai_type, str):
         return None
 
+    if "anthropic" in ai_type:
+        return "anthropic"
+    elif "openai" in ai_type:
+        return "openai"
+
     return ai_type
 
 

diff --git a/tests/integrations/langchain/test_langchain.py b/tests/integrations/langchain/test_langchain.py
--- a/tests/integrations/langchain/test_langchain.py
+++ b/tests/integrations/langchain/test_langchain.py
@@ -2005,13 +2005,13 @@
     [
         # Real LangChain _type values (from _llm_type properties)
         # OpenAI
-        ("openai-chat", "openai-chat"),
+        ("openai-chat", "openai"),
         ("openai", "openai"),
         # Azure OpenAI
-        ("azure-openai-chat", "azure-openai-chat"),
+        ("azure-openai-chat", "openai"),
         ("azure", "azure"),
         # Anthropic
-        ("anthropic-chat", "anthropic-chat"),
+        ("anthropic-chat", "anthropic"),
         # Google
         ("vertexai", "vertexai"),
         ("chat-google-generative-ai", "chat-google-generative-ai"),

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

if not ai_type or not isinstance(ai_type, str):
return None

return ai_type
Copy link

Choose a reason for hiding this comment

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

Raw _type values break gen_ai.system consistency with other integrations

Medium Severity

_get_ai_system returns the raw LangChain _type value (e.g. "anthropic-chat", "openai-chat") instead of a normalized provider name. The Anthropic integration sets gen_ai.system to "anthropic" and the OpenAI integration uses "openai", matching OTel semantic conventions. The old code also normalized to these values. Now the same provider gets different gen_ai.system values depending on whether it's called directly or through LangChain, breaking filtering/grouping in the Sentry UI for existing users.

Additional Locations (1)
Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

This is intentional, see #5707 (comment)

}


@pytest.mark.parametrize(
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add an assertation that gen_ai.system is correctly set in one of the tests that use langchain organically, i.e., like a user would interact with it. In one or all of these 🙏 .

  • test_langchain_text_completion()
  • test_langchain_create_agent()
  • test_tool_execution_span()

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.

2 participants