BUG: LangChain Code node code reads as empty in some cases

Describe the problem/error/question

See the workflow below. It’s basically the default code that comes with the node, but with a empty line at the beginning. The point is that if that line is not empty, the code reads as empty and I get the No code for "Execute" set on node "LangChain Code error.

If the first line is not empty, in this case, I can’t even copy here, because it would render the workflow as empty on the visualization.

I can let the first line be the require one, if (and only if) the next line is not empty.

So in summary:

This gives me No code for "Execute" set on node "LangChain Code error

const { PromptTemplate } = require('@langchain/core/prompts');

const query = 'Tell me a joke';
const prompt = PromptTemplate.fromTemplate(query);
const llm = await this.getInputConnectionData('ai_languageModel', 0);
let chain = prompt.pipe(llm);
const output = await chain.invoke();
return [ {json: { output } } ];

This DOES NOT give me No code for "Execute" set on node "LangChain Code error

//Empty Line
const { PromptTemplate } = require('@langchain/core/prompts');

const query = 'Tell me a joke';
const prompt = PromptTemplate.fromTemplate(query);
const llm = await this.getInputConnectionData('ai_languageModel', 0);
let chain = prompt.pipe(llm);
const output = await chain.invoke();
return [ {json: { output } } ];

This also DOES NOT give me No code for "Execute" set on node "LangChain Code error

const { PromptTemplate } = require('@langchain/core/prompts');
const query = 'Tell me a joke';
const prompt = PromptTemplate.fromTemplate(query);
const llm = await this.getInputConnectionData('ai_languageModel', 0);
let chain = prompt.pipe(llm);
const output = await chain.invoke();
return [ {json: { output } } ];

When the node code executes, I get another error Expected a Runnable, function or object. [line 7], regarding the let chain = prompt.pipe(llm) line, but that’s subject for another topic.

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.38.1
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): k8s
  • Operating system: ubuntu

Hi @miguel-mconf,

Thank you so much for sharing this and describing all the steps!

I’ve raised the issue with our Nodes team :muscle:

Hi @miguel-mconf,

What seems to happen here is that the default code is expecting only one possible language model input.

The reason that the first code-block is giving you the No code for "Execute" set on node error, is because that’s the default code, and you need to edit it in order to have the node register it as being set.

The other code examples give you an error, because the langchain pipe expects a model, not an array (the getInputConnectionData function returns an array if you’ve set the number of allowed language models inputs to -1 or higher that 1).

We’ll update the code-example a bit to explain that last detail a bit better.

1 Like

New version [email protected] got released which includes the GitHub PR 10056.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.