Dynamic HTTP request body in AI agent

Hi everyone,

I’ve been stuck on this for hours and could really use some guidance.

I’m trying to build an AI agent that generates a draft invoice based on a simple voice prompt.
With the API I’m using, once the (empty) invoice is created, a route is called to add articles in the form of a structured array—each lines object representing an article. Here’s an example of the request body:

{
  "lines": [
    {
      "unitPrice": "{unitPrice}",
      "quantity": "{quantity}",
      "quantityUnit": "unit",
      "designation": "{designation}",
      "type": "sale_of_goods",
      "vatCode": "FR_2000",
      "isDeliveryOfGoods": true
    }
  ]
}

As you can see, I’ve replaced some values with placeholders ({}) that the model should fill in. The goal is to be able to say something like “Add 40 books and 10 hats to the invoice”, and have the model populate the appropriate values.

The problem is: while the data is correctly filled, the agent ends up calling the route twice, each time with a single article, instead of calling it once with both articles in the same payload.

I’ve tried generating a proper JSON with both objects using CodeTool and feeding it into the HTTP Request, but I can’t figure out how to make it work—or even if it’s possible at all.

Here’s the link to the workflow:

  • n8n version: 1.83.2
  • Database (default: SQLite): In-memory
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Cloud
  • Operating system: macOS

I’ve also been trying to use a {placeholder} and instruct the AI Agent to fill in the correct JSON format using either a system prompt or a placeholder definition, but it doesn’t work — the AI Agent returns the error: “Received tool input did not match expected schema.”

Where are you my hero ? :joy:

Hi, I think you should use something like. fromAI… Check some of the templates for examples of this. The templates are a good source for learning and to get ideas for testing.

Hi @jcuypers,

I tried that before with no success … Do you have a specific template in mind ? If i refer to the documentation, $fromAI is not available on HTTP nodes …

Hi, I don’t have a handy answer for you TBH. what i noticed is that your instructions to your model are very limited. both on the system message as well as on the tool itself. I’m sure that with engineering it properly, you might already solve your problem. Just by mentioning on your system prompt are tool description. The tool needs to be provided with an array of items, of which each item need to be of format x .

I have not used this with HTTP request, but with tools via MCP it works wonders. don’t forget that everything you type there gets injected into your agent so it can “understand” what it is supposed to do.

Unfortunately this is a trial and error approach.

As I didn’t try it with HTTP request directly as a tool i’m not sure how it compares to anything else

Reg,
J.