Call langchain with data from n8n node

Hello, how can I pass json data to a python file from an n8n node? In order to run Langchain over it and deliver the finished output back to the n8n node.

The implemented agents look great in animations, but unfortunately in practice they are still very buggy. For example, the known and unfixed bug with the outparser error. Or missing options to adjust vector dimensions in Qdrant Retriever. Also that stream=true cannot be used… This is all just a waste of time and that’s why I would like to just run langchain in python. But how do I get a connection to n8n?

No imports from … are allowed in the Python code node. As n8n does use Pyodide underneath the hood, which does not support the request module. You can’t load a Python function and pass Json data directly to it.

Actually, the only way left is to use the command line with the node execute command:

cd /n8n/ && python my_script.py {{ $json.data }}

But how do I get the Json data in Python:

[
{
“data”: [
{
“value1”: “1”,
“value2”: “2”,
“value3”: “3”,
}
]
}
]

It looks like your topic is missing some important information. Could you provide the following if applicable.

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

n8n version: Version 1.45.1
Database (default: SQLite): none (or SQLite)
n8n EXECUTIONS_PROCESS setting (default: own, main): ? default ?
Running n8n via npm
Operating system: Windows 10

Welcome to the community @eyeffect :tada:
Thanks for all your feedback around how we can improve our Langchain integration and code node functionalities. Could you maybe add links to relevant feature requests and forum posts, it would be helpful for us to know which issues you’re referring to.

Regarding your question on how to pass json data in your execute command node, you can use the stringify method like so:

{{ JSON.stringify($json.data) }}`

I tested out the following workflow with a simple python script that prints out the first argument in the shell command which seems to work for me.

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