Skip to content

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

Merged
ericapisani merged 6 commits intomasterfrom
ep/broaden-langgraph-model-support-6d0
Mar 25, 2026
Merged

feat(langchain): Broaden AI provider detection beyond OpenAI and Anthropic#5707
ericapisani merged 6 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 📊

7 passed | Total: 7 | Pass Rate: 100% | Execution Time: 3.15s

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 15257 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 ✨

Langchain

  • Broaden AI provider detection beyond OpenAI and Anthropic by ericapisani in #5707
  • Update LLM span operation to gen_ai.generate_text by ericapisani in #5796

Internal Changes 🔧

Langchain

  • Add text completion test by alexander-alderman-webb in #5740
  • Add tool execution test by alexander-alderman-webb in #5739
  • Add basic agent test with Responses call by alexander-alderman-webb in #5726
  • Replace mocks with httpx types by alexander-alderman-webb in #5724
  • Consolidate span origin assertion by alexander-alderman-webb in #5723
  • Consolidate available tools assertion by alexander-alderman-webb in #5721

Other

  • Temporarily stop running litellm tests by alexander-alderman-webb in #5851

🤖 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.

Autofix Details

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)

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.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb left a comment

Choose a reason for hiding this comment

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

LGTM!

@ericapisani ericapisani merged commit 72483bb into master Mar 25, 2026
167 of 169 checks passed
@ericapisani ericapisani deleted the ep/broaden-langgraph-model-support-6d0 branch March 25, 2026 09:31
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