> For the complete documentation index, see [llms.txt](https://docs.n8n.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts/langchain-code-node.md).

# LangChain Code node

n8n provides these methods to make it easier to perform common tasks in the [LangChain Code node](/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.code.md).

{% hint style="info" %}
**LangChain Code node only**

These variables are for use in expressions in the LangChain Code node. You can't use them in other nodes.
{% endhint %}

| Method                                                           | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `this.addInputData(inputName, data)`                             | <p>Populate the data of a specified non-main input. Useful for mocking data.</p><ul><li><code>inputName</code> is the input connection type, and must be one of: <code>ai\_agent</code>, <code>ai\_chain</code>, <code>ai\_document</code>, <code>ai\_embedding</code>, <code>ai\_languageModel</code>, <code>ai\_memory</code>, <code>ai\_outputParser</code>, <code>ai\_retriever</code>, <code>ai\_textSplitter</code>, <code>ai\_tool</code>, <code>ai\_vectorRetriever</code>, <code>ai\_vectorStore</code></li><li><code>data</code> contains the data you want to add. Refer to <a href="/spaces/rPN1zU5jaYNvwH7RzxqA/pages/4w4R7N2ysLi9xAC7Jfde">Data structure</a> for information on the data structure expected by n8n.</li></ul>   |
| `this.addOutputData(outputName, data)`                           | <p>Populate the data of a specified non-main output. Useful for mocking data.</p><ul><li><code>outputName</code> is the input connection type, and must be one of: <code>ai\_agent</code>, <code>ai\_chain</code>, <code>ai\_document</code>, <code>ai\_embedding</code>, <code>ai\_languageModel</code>, <code>ai\_memory</code>, <code>ai\_outputParser</code>, <code>ai\_retriever</code>, <code>ai\_textSplitter</code>, <code>ai\_tool</code>, <code>ai\_vectorRetriever</code>, <code>ai\_vectorStore</code></li><li><code>data</code> contains the data you want to add. Refer to <a href="/spaces/rPN1zU5jaYNvwH7RzxqA/pages/4w4R7N2ysLi9xAC7Jfde">Data structure</a> for information on the data structure expected by n8n.</li></ul> |
| `this.getInputConnectionData(inputName, itemIndex, inputIndex?)` | <p>Get data from a specified non-main input.</p><ul><li><code>inputName</code> is the input connection type, and must be one of: <code>ai\_agent</code>, <code>ai\_chain</code>, <code>ai\_document</code>, <code>ai\_embedding</code>, <code>ai\_languageModel</code>, <code>ai\_memory</code>, <code>ai\_outputParser</code>, <code>ai\_retriever</code>, <code>ai\_textSplitter</code>, <code>ai\_tool</code>, <code>ai\_vectorRetriever</code>, <code>ai\_vectorStore</code></li><li><code>itemIndex</code> should always be <code>0</code> (this parameter will be used in upcoming functionality)</li><li>Use <code>inputIndex</code> if there is more than one node connected to the specified input.</li></ul>                         |
| `this.getInputData(inputIndex?, inputName?)`                     | Get data from the main input.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `this.getNode()`                                                 | Get the current node.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `this.getNodeOutputs()`                                          | Get the outputs of the current node.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `this.getExecutionCancelSignal()`                                | Use this to stop the execution of a function when the workflow stops. In most cases n8n handles this, but you may need to use it if building your own chains or agents. It replaces the [Cancelling a running LLMChain](https://js.langchain.com/docs/modules/chains/foundational/llm_chain#cancelling-a-running-llmchain) code that you'd use if building a LangChain application normally.                                                                                                                                                                                                                                                                                                                                                   |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.n8n.io/build/code-in-n8n/use-built-in-shortcuts/langchain-code-node.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
