st Content:
Problem Description:
I am using the AI Agent in n8n to collect user input and send it to the HTTP Request node. However, when I map the output from the AI Agent to {{$fromAI('json')}}, the HTTP Request node fails with errors.
- Sometimes the request receives an empty body (
query: {}) instead of the expected JSON.
- If I manually input data, the HTTP Request node works fine.
- Authorization (Bearer Token) is properly set in the headers.
- Tried using {{$json}} instead of $fromAI(‘json’), but still facing issues.
Describe the problem/error/question
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system:
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 veersion : 1.78.1
database : SQLlite
n8n executions_process : default
Running n8n : npm
Operating system. : linux
Hey @Bhojraj_pilaniya1,
I see that your AI Agent’s output is not properly mapping to the HTTP Request node , which sometimes causes an empty request body (query: {}) . Here’s how to fix it:
1. Ensure the AI Agent Outputs Proper JSON
Modify the System Message in the AI Agent to force structured output:
When responding, always return valid JSON. Example format:
{
“query”: {
“key1”: “value1”,
“key2”: “value2”
}
}
Do not include extra text, explanations, or formatting outside this JSON structure.
• Then test with:
Example input: “Generate a request for user details”
• The AI must return structured JSON, not plain text.
2. Update the JSON Mapping in the HTTP Request Node
Instead of:
{{$fromAI(‘json’)}}
Use:
{{$json[“query”] || “{}”}}
• This ensures a fallback value ({}) if query is missing.
3. Debug the AI Output Before the HTTP Request
• Add a Function node between the AI Agent and HTTP request.
• Inside the Function node, use:
return [{ “debug”: JSON.stringify($json) }];
• Run the workflow and check the debug output to confirm the AI sends valid JSON.
Try these fixes and let me know if the issue persists! 