Postgres Tool - Set By Agent Missing

I noticed today that the “Defined by Agent” utility is missing for the Postgres Execute Query operation when the node is attached to the AI Agent Node.

Below, I had to define it.

In other options, the utilitiy to quickly add “Define by the Agent” is visible in the UI. For example:

In short, was there an intentional reason this feature would be omitted from the the Execute Query capability when Postgres is added as a tool?

Hi @datanerdery3

The Query field is marked noDataExpression: true in the 2.45.7 code, and the shared UI hides the AI-fill shortcut for fields with that flag. That explains the difference from Schema/Table in your screenshots.

Postgres separately evaluates {{ ... }} expressions inside the SQL text. Manually adding $fromAI() is the documented alternative to the shortcut, which is the route you’re already using.

That explains the missing control, but I couldn’t confirm whether the original omission was intentional. Which n8n version are you using?

We are on 2.46.3 n8n Cloud, Pro license. Obviously I can get around it, but more curious than anything as to why this convenience feature wouldn’t be available when the Postgres tool is added to an Agent, as I show above.

I haven’t seen an official reason for it. My guess is Execute Query takes a free-text SQL field, so it’s treated differently from the structured fields. A workaround is to write the query as an expression using $fromAI(‘param_name’, ‘description’, ‘string’) inside the field. That gives you the same result as the button.

I traced the flag back to the SQL editor overhaul from June 2023. That change introduced one input mode combining static SQL and embedded expressions, and added noDataExpression: true alongside Postgres’s own expression evaluation:

The review also discusses applying that flag consistently to SQL query fields. In the 2.46.3 source, the AI-fill control still skips fields with that flag.

So the missing shortcut follows an older SQL editor design. I haven’t found a separate decision to deliberately exclude it for Postgres Agent tools.

I don’t think it was removed on purpose for tools specifically, it comes from how that field is defined. In the Postgres node the Query field is marked noDataExpression (it’s the SQL editor where you write {{ }} inline instead of flipping the field to Expression mode), and the editor only offers the “let the model define this” button on fields without that flag. So you won’t get the sparkle button on Query, but you can still use $fromAI() there.

Two ways to set it up:

1. Fixed SQL, model fills in only the values (what I’d do)

SELECT id, status, total
FROM orders
WHERE customer_email = $1
  AND created_at >= $2

Then Add option → Query Parameters. That one is a normal string field, so the button shows up there, or type it yourself:

{{ $fromAI('customer_email', 'Email of the customer', 'string') }},{{ $fromAI('since', 'Start date in YYYY-MM-DD format', 'string') }}

The values are sent as query parameters, so they get escaped and the model can’t change the shape of the query.

2. Let the agent write the whole query

Type the expression straight into the Query editor:

{{ $fromAI('sql_query', 'One read-only PostgreSQL SELECT statement', 'string') }}

When the node is turned into a tool, n8n collects $fromAI() calls from all of its parameters, not only the ones that have the button, so sql_query still ends up in the tool’s input schema. If you go this way, give that credential a database user with read-only access to just the tables the agent needs, because the model can send anything that user is allowed to run.

Thanks for the callout, and the fromAI call is what I added to make it work. I don’t need to belabor this but with that feature sprinkled in, this feels like the exact use case where it should be included … an Agent writing SQL.

Yeah I agree, it’s a bit odd that the one field an agent is most likely to write into is the one without the button. Worth posting as a feature request on the forum so the team can see people want it.