Learning resourcesReviewed · n8n

n8n LangChain Code Node Built-in Methods

This n8n reference explains helper methods for developers building AI workflows, but those helpers work only in the LangChain Code node. It documents access to workflow data, mock data helpers, node information and execution cancellation.

Researched 23 Nov 2026

In short.

This n8n reference explains helper methods for developers building AI workflows, but those helpers work only in the LangChain Code node. Its seven method entries cover main and non-main connection data, mock input and output data, node information and cancellation support. It is useful as a focused lookup reference; setup instructions, complete examples, compatibility versions and costs are not established by this page. No methods or workflows were executed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage includes the complete page at [https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts/langchain-code-node.md], including all seven method entries, the node-only notice and related-resource links. Linked pages, including the documentation index, node overview, data-structure guide and related shortcut references, are excluded. Method behavior, payload compatibility, cancellation and complete workflows were not executed or tested.

The overview

Identity

The resource is the LangChain Code node shortcut reference in n8n's documentation, available at [https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts/langchain-code-node.md]. It documents built-in methods for expressions in that node.

This page is a reference for an existing feature. It contains method signatures and descriptions, rather than a downloadable integration or a complete workflow.

Assessment

The page is useful when you already have a LangChain Code node and need to identify the helper for a particular task. Its most actionable details are the distinction between main and non-main inputs, the supported AI connection types and the requirement to pass 0 for itemIndex.

It offers limited help with learning the feature from scratch: there is no complete example, installation procedure or explanation of return values. Runtime behavior and reliability were not assessed.

Users

The strongest fit is developers writing expressions in n8n's LangChain Code node, especially those handling AI component connections, supplying mock data or building custom chains and agents.

Beginners can use the page to identify available helpers, but will need additional guidance on creating the node, connecting components and formatting n8n data. Those steps are not explained here.

Capabilities

this.addInputData(inputName, data) and this.addOutputData(outputName, data) populate specified non-main inputs and outputs. The page identifies mocking data as a use for both methods.

this.getInputConnectionData(inputName, itemIndex, inputIndex?) retrieves data from a specified non-main input. this.getInputData(inputIndex?, inputName?) retrieves main-input data. this.getNode() retrieves the current node, and this.getNodeOutputs() retrieves its outputs.

this.getExecutionCancelSignal() supports stopping a function when the workflow stops. The documentation says n8n handles this in most workflows, while custom chains or agents may need it.

Using it

Requirements

The page explicitly restricts these built-in methods and variables to expressions in the LangChain Code node. They cannot be used in other nodes.

The data-supplying methods expect n8n's data structure, but its schema is delegated to a linked guide. Minimum n8n or LangChain versions, hosting availability, credentials and package requirements are not specified.

Mechanism

The helpers are called through this and distinguish ordinary main-input data from non-main AI connections. The three methods with named non-main connections list these types: ai_agent, ai_chain, ai_document, ai_embedding, ai_languageModel, ai_memory, ai_outputParser, ai_retriever, ai_textSplitter, ai_tool, ai_vectorRetriever and ai_vectorStore.

For this.getInputConnectionData(inputName, itemIndex, inputIndex?), itemIndex must always be 0. The page reserves that parameter for upcoming functionality. Use the optional inputIndex when multiple nodes connect to the specified input.

The cancellation helper provides a way for custom function execution to respond when a workflow stops. Its return type and the code needed to consume it are not documented here.

Setup

Apply the reference within a LangChain Code node expression. Identify whether the task concerns the main input or a named AI connection, then use the corresponding method signature.

Before supplying mock data, consult the linked data-structure guide at [https://docs.n8n.io/build/work-with-data/understand-n8ns-data-structure.md]. Its contents are outside this page's scope, so the required payload format is unknown here. Node creation, configuration and installation steps are also absent.

Example

An illustrative expression derived from the documented signature is this.getInputConnectionData('ai_languageModel', 0). It requests data from the ai_languageModel input and uses the required itemIndex value of 0.

If multiple nodes connect to that input, the page directs you to supply the third argument, inputIndex. It does not establish the returned object's shape or how to invoke it. This illustration was not executed, and the page supplies no complete working example.

Assessment & evidence

Limitations

These helpers are restricted to the LangChain Code node. The page does not specify return schemas, error behavior, asynchronous usage, connection-index ranges or version compatibility. It also provides no benchmarks or runtime results.

The addOutputData entry describes a non-main output but labels outputName as an input connection type. That wording is unresolved on the page. The itemIndex parameter also cannot be treated as general item selection: the documented instruction is to always use 0.

Reasoning

The practical value is precision when writing node expressions: the reference identifies which helper accesses each kind of data and gives constraints that could otherwise be missed, particularly the fixed itemIndex value and optional inputIndex.

That supports using it as a focused lookup reference. It does not establish that a proposed workflow will execute successfully, that connected components are compatible or that cancellation is implemented correctly in custom code.

Alternatives

For adjacent questions, the page links to general built-in shortcuts at [https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts.md], JMESPath, HTTP-node helpers and n8n metadata. Based on their titles, these are starting points for other shortcut topics.

The linked pages were not assessed. This reference provides no comparison with other tools or evidence that those related resources offer equivalent LangChain connection handling.

Evidence

The evidence is the complete documentation page at [https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts/langchain-code-node.md]. It contains seven method entries, parameter descriptions, a LangChain Code node-only notice and links to related documentation.

The page documents intended behavior. It includes no execution traces, measured outcomes or complete workflow demonstrations, and nothing was executed for this report.

Access & freshness

Costs

The page provides no prices, subscription requirements, plan restrictions or usage charges. The cost of using these helpers in an n8n workflow is unknown from this source, including any charges associated with connected services.

Rights

The supplied page contains no license terms or express redistribution permission. Rights to redistribute the documentation, and licensing conditions for the underlying software, are unknown from this source.

Freshness

The supplied page was captured on 23 November 2026 at 15:18:44 UTC. It states no publication date, last-updated date or applicable software version.

Its reference to upcoming itemIndex functionality is undated. Whether that functionality exists in any particular n8n release is unknown; the captured instruction remains to pass 0.

Actions

Use this page when choosing a helper inside a LangChain Code node. Distinguish main-input access from AI connection access, keep itemIndex at 0 and supply inputIndex when multiple nodes connect to the specified input.

Before implementation, confirm compatibility with your installed n8n version and consult the linked node overview at [https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.code.md] for context. Resolve payload formats, return values and cancellation handling before relying on them in a workflow.

Evidence for this report

selected-page.txtselected · checked 2026-11-23