SubNode Code Tool With AI Agent Error: Expected String but Received Object

I’m encountering an issue in n8n where a Function node is returning a string instead of an object.

Problem Description: In my workflow, I use a Subnode Code Tool to process data from an AI AGENT and expect it to return an GET REQUEST. However, the node outputs a object, causing this error: “The response property should be a string, but it is an object”

Error Message: Subsequent nodes report errors indicating they cannot process the input data because it’s a string rather than the expected object.

Workflow Details: Here’s the relevant portion of my workflow:

n8n Setup Information: + OpenProject 15.1.0. Community Edition

  • n8n version: 1.72.1 * Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting: own, main (default)
  • Running n8n via: Docker
  • Operating system: Ubuntu 20.04

Steps Taken: I’ve reviewed the Function node’s code to ensure it returns an string. Despite this, the output remains a object. I’ve also consulted the n8n documentation on and test with a simple HTTP node same REQUEST and it works perfect. So i have no clue about this. Thanks :wink:

n8n Docs

and related community discussions, but haven’t found a solution.

Request for Assistance: Could someone help me identify why the Function node returns a string instead of an object and how to resolve this issue?

Thank you in advance for your support.

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:

Hi @Juan_Pablo_Sanchez

The code node may return the object alright but because it’s fed into the AI agent, the agent will return everything as string by default (because it’s an LLM that works with text). However, you can use the Require Specific Output Format option and then implement the parsing logic you need for it to return the object.

Have a look in our documentation: Basic LLM Chain node documentation | n8n Docs

HI Ria , thanks for the quick response!,. Not sure if your solution is to enable Require Specific Output Format and ADD a Auto-fixing Output Parser with a min Json Schema . In this case i just continue to receive the same error “There was an error: “Binary data is not supported”” As per my understanding the Auto-fixing Output Parser is executed After . Please see OUTPUT here

So i´m still looking to fix this :wink: any help super wellcome ! thanks! :wink:

Hi @Juan_Pablo_Sanchez

From the screenshot you’ve shared, this is a different error now and you’re using the HTTP request tool node. Maybe I am not fully understanding what you’re trying to do in your workflow.

Are you trying to get the AI Agent to do a HTTP request call and you need a specific format for the request? If so, what exactly does the API you’re trying to call expect in the request?

Perhaps the Agent is not the right solution here if you only need the AI to provide the correct format. An agent is designed to focus on one specific task only. The tool nodes that you connect to the agent, are supposed to only serve the agent as, well, tools to get that specific task done correctly. I think what you’re trying to do here is to make the agent perform a whole series of tasks, which is not what it’s designed for.

You need to think about what your tasks are.

  1. Get the user’s input into the right format for the HTTP request
  2. Make the HTTP request
  3. Get the HTTP response in the right format for further processing of your workflow

The Structured Output Parsing functionality is something that is applied to the final output of the Agent node (i.e. after tools have been called). In fact, if this is the only thing you need to do with the input data you could use other nodes for that (e.g. the LLM Chain node). You can then pass on the structured output to a simple HTTP request node or if you need another more specific task to be performed you may use another Agent for that, and so on.

Have a look at this POC to demonstrate the different ways in which you could build your workflow to achieve what you’re looking for.

Hope this helps! :slight_smile: :christmas_tree:

May thanks Ria for the explanation and the POC.
Let me rephrase everything since, as you mentioned, I have now switched to using an HTTP REQUEST TOOL. Here’s the flow:

The flow is very simple. Based on a chatInput request to list projects, the AI Agent1 processes it, identifying that the task can be performed using the TOOL “list_openproject_projects1” and executes it. The GET request has been tested with POSTMAN and executes correctly. During its execution in the flow, however, the AGENT receives a response from the subnode indicating that “Binary data is not supported”.

ACTUAL FLOW:

ERROR screen capture:

Execution of the flow screen capture:

So, I know I can work around this by calling another workflow and managing it from there using a standard HTTP node, etc. The point here is that I’d like to understand why the response is labeled as binary data not supported, even though the same GET request in POSTMAN or in a standard HTTP node returns JSON.

This is the answer you should receive:


[

{

"data": "{"_type":"Collection","total":2,"count":2,"pageSize":20,"offset":1,"_embedded":{"elements":[{"_type":"Project","id":2,"identifier":"your-scrum-project","name":"Scrum project","active":true,"public":true,"description":{"format":"markdown","raw":"This is a short summary of the goals of this demo Scrum project.","html":"<p class=\"op-uc-p\">This is a short summary of the goals of this demo Scrum project.</p>"},"createdAt":"2024-12-21T14:59:55.856Z","updatedAt":"2024-12-21T14:59:55.856Z","statusExplanation":{"format":"markdown","raw":"All tasks are on schedule. The people involved know their tasks. The system is completely set up.","html":"<p class=\"op-uc-p\">All tasks are on schedule. The people involved know their tasks. The system is completely set up.</p>"},"_links":{"self":{"href":"/api/v3/projects/2","title":"Scrum project"},"createWorkPackage":{"href":"/api/v3/projects/2/work_packages/form","method":"post"},"createWorkPackageImmediately":{"href":"/api/v3/projects/2/work_packages","method":"post"},"workPackages":{"href":"/api/v3/projects/2/work_packages"},"storages":[],"categories":{"href":"/api/v3/projects/2/categories"},"versions":{"href":"/api/v3/projects/2/versions"},"memberships":{"href":"/api/v3/memberships?filters=%5B%7B%22project%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%222%22%5D%7D%7D%5D"},"types":{"href":"/api/v3/projects/2/types"},"update":{"href":"/api/v3/projects/2/form","method":"post"},"updateImmediately":{"href":"/api/v3/projects/2","method":"patch"},"delete":{"href":"/api/v3/projects/2","method":"delete"},"schema":{"href":"/api/v3/projects/schema"},"status":{"href":"/api/v3/project_statuses/on_track","title":"On track"},"ancestors":[],"projectStorages":{"href":"/api/v3/project_storages?filters=%5B%7B%22projectId%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%222%22%5D%7D%7D%5D"},"parent":{"href":null}}},{"_type":"Project","id":1,"identifier":"demo-project","name":"Demo project","active":true,"public":true,"description":{"format":"markdown","raw":"This is a short summary of the goals of this demo project.","html":"<p class=\"op-uc-p\">This is a short summary of the goals of this demo project.</p>"},"createdAt":"2024-12-21T14:59:53.511Z","updatedAt":"2024-12-21T14:59:53.511Z","statusExplanation":{"format":"markdown","raw":"All tasks are on schedule. The people involved know their tasks. The system is completely set up.","html":"<p class=\"op-uc-p\">All tasks are on schedule. The people involved know their tasks. The system is completely set up.</p>"},"_links":{"self":{"href":"/api/v3/projects/1","title":"Demo project"},"createWorkPackage":{"href":"/api/v3/projects/1/work_packages/form","method":"post"},"createWorkPackageImmediately":{"href":"/api/v3/projects/1/work_packages","method":"post"},"workPackages":{"href":"/api/v3/projects/1/work_packages"},"storages":[],"categories":{"href":"/api/v3/projects/1/categories"},"versions":{"href":"/api/v3/projects/1/versions"},"memberships":{"href":"/api/v3/memberships?filters=%5B%7B%22project%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%221%22%5D%7D%7D%5D"},"types":{"href":"/api/v3/projects/1/types"},"update":{"href":"/api/v3/projects/1/form","method":"post"},"updateImmediately":{"href":"/api/v3/projects/1","method":"patch"},"delete":{"href":"/api/v3/projects/1","method":"delete"},"schema":{"href":"/api/v3/projects/schema"},"status":{"href":"/api/v3/project_statuses/on_track","title":"On track"},"ancestors":[],"projectStorages":{"href":"/api/v3/project_storages?filters=%5B%7B%22projectId%22%3A%7B%22operator%22%3A%22%3D%22%2C%22values%22%3A%5B%221%22%5D%7D%7D%5D"},"parent":{"href":null}}}]},"_links":{"self":{"href":"/api/v3/projects?filters=%5B%5D&offset=1&pageSize=20"},"jumpTo":{"href":"/api/v3/projects?filters=%5B%5D&offset=%7Boffset%7D&pageSize=20","templated":true},"changeSize":{"href":"/api/v3/projects?filters=%5B%5D&offset=1&pageSize=%7Bsize%7D","templated":true},"representations":[{"href":"/projects.csv?filters=%5B%5D&offset=1&pageSize=20","identifier":"csv","type":"text/csv","title":"CSV"},{"href":"/projects.xls?filters=%5B%5D&offset=1&pageSize=20","identifier":"xls","type":"application/vnd.ms-excel","title":"XLS"}]}}"

}

]

Thanks for any clarification on this and :christmas_tree::sparkles: Merry Christmas! :santa::gift:strong text

Hi @Juan_Pablo_Sanchez

Ahh, got ya! :wink:

So I think what’s happening is that you have your HTTP tool configured to expect a JSON response, but the API is not returning that. It could be a binary, it could be something else, but the error Binary data is not supported is basically the Agent telling you “Hey that’s not JSON.”

Given that in your header you’re asking for Accept-encoding: gzip, deflate, br the API is probably sending you exactly that. So you could try to change the Expected Response Type to Text and see if the Agent can work with that.

image

Thank you so much for your suggestion! :pray: I tried changing the Expected Response Type to Text, but I’m still getting the same result: “Binary data is not supported.” :confused: I also tried removing the header, as it’s not strictly necessary, and tested with the Truncate Response option both enabled and disabled, but unfortunately, none of these worked. :weary: Oh no, this is turning into a tough bug to crack! :wrench::bug::blush:
AI AGENT LOG

SubNode Config Detail

Hi @Ria,
Hope all is well! I’m not sure if you’ve seen my last reply. Could you please take a look when you get a chance? Let me know if you need any additional details.

Thanks in advance for your help! :blush:

Best regards,
JP

Hi @Juan_Pablo_Sanchez

Sorry for the delayed response - I actually caught a bug myself and was ill for a few days :microbe: haha

Anyways, so it looks like the API really returns binary data and in this case, we don’t support binary data for tools at the moment. Like mentioned before, you could use a separate workflow / sub-workflow-tool to transform the binary data that you get with the http node into some text-response.

Granted, it’s a bit cumbersome, but that’s the only way we support it right now…

Hi RIA, I’ve tested the API with Postman and can confirm it returns a JSON response, not binary, so it seems the issue might be with the subnode? any idea how to fix it? thanks again. @ria :wink:

Hey @Juan_Pablo_Sanchez

sorry for the late reply.
We’re looking into this as it could potentially be a bug.

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