Skip to content

chore: Upgrade langchain packages - #26892

Merged
schrothbn merged 3 commits into
masterfrom
ai-2182-strip-empty-text-content-blocks-when-using-openai-node-with
Mar 12, 2026
Merged

schrothbn merged 3 commits into
masterfrom
ai-2182-strip-empty-text-content-blocks-when-using-openai-node-with

Conversation

@schrothbn

Copy link
Copy Markdown
Contributor

Summary

Bumps @langchain/core from 1.1.8 to 1.1.31 to pick up the fix for langchain-ai/langchainjs#9995, which strips empty text content blocks before sending
messages to the API.

Root cause: When an AI Agent uses tool-calling with an Anthropic model via the OpenAI Chat Model node, the assistant message was constructed with "content": "" alongside the tool_calls block. Anthropic (and Anthropic-compatible) endpoints reject this with 400. OpenAI ignores empty content silently, so only Anthropic-compatible backends were affected.

The fix in @langchain/core@1.1.22+ adds a content.length > 0 guard in convertToV1FromChatCompletions before pushing a text block, so empty strings are never sent.

Additional package bumps pulled in alongside the core upgrade:

  • langchain: 1.2.3 → 1.2.30 (required — 1.2.30 now correctly pins @langchain/core: ^1.1.31 as its peer dep)
  • @langchain/anthropic: 1.1.3 → 1.3.22 (compatible, no breaking changes)
  • @langchain/google-genai: 2.1.10 → 2.1.24 (required — 2.1.10 had an exact peer dep on @langchain/core@1.1.15 which conflicted with 1.1.31)
  • @langchain/google-vertexai: 2.1.10 → 2.1.24 (same reason as above)

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/AI-2182

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

@schrothbn
schrothbn force-pushed the ai-2182-strip-empty-text-content-blocks-when-using-openai-node-with branch from 14aecda to 498bc9b Compare March 11, 2026 11:56
@n8n-assistant n8n-assistant Bot added the n8n team Authored by the n8n team label Mar 11, 2026
@codecov

codecov Bot commented Mar 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@blacksmith-sh

This comment has been minimized.

@schrothbn
schrothbn force-pushed the ai-2182-strip-empty-text-content-blocks-when-using-openai-node-with branch from 4d1bb0e to 32b9783 Compare March 12, 2026 07:46
@codecov

codecov Bot commented Mar 12, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

Affected Assets, Files, and Routes:

view changes for bundle: editor-ui-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/worker-*.js 2.93MB 2.95MB 21924.59% ⚠️
assets/worker-*.js -2.93MB 13.37kB -99.55%

@schrothbn
schrothbn marked this pull request as ready for review March 12, 2026 08:24
@schrothbn
schrothbn requested review from a team and mutdmour and removed request for a team March 12, 2026 08:24

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 3 files

Architecture diagram
sequenceDiagram
    participant User as "User / Workflow"
    participant Node as "n8n AI Node (OpenAI Model)"
    participant Core as "@langchain/core (v1.1.31)"
    participant API as "LLM Endpoint (Anthropic/OpenAI)"

    Note over User,API: Message Flow with Tool Calling

    User->>Node: Execute Agent with Tool
    Node->>Core: formatMessages(history)
    
    Note over Core: CHANGED: convertToV1FromChatCompletions()
    
    Core->>Core: Inspect message blocks
    
    alt Content is empty ('') AND Tool Calls present
        Core->>Core: NEW: Strip empty text block
    else Content is non-empty
        Core->>Core: Preserve text block
    end
    
    Core-->>Node: Sanitized Message Object
    
    Node->>API: POST /chat/completions
    Note right of API: Payload now lacks empty 'content' strings
    
    alt Anthropic-compatible Backend
        API-->>Node: 200 OK (Success)
    else Legacy Behavior (pre-fix)
        Note right of API: Would return 400 Bad Request if content: ''
        API-->>Node: 400 Error
    end
    
    Node-->>User: Tool Output / Agent Response
Loading

@schrothbn
schrothbn added this pull request to the merge queue Mar 12, 2026
Merged via the queue into master with commit da61e72 Mar 12, 2026
49 checks passed
@schrothbn
schrothbn deleted the ai-2182-strip-empty-text-content-blocks-when-using-openai-node-with branch March 12, 2026 10:42
cstuncsik pushed a commit that referenced this pull request Mar 16, 2026
@n8n-assistant

n8n-assistant Bot commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Got released with n8n@2.13.0

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

Labels

n8n team Authored by the n8n team Released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants