Yes, that is correct, but I would keep the responsibility clearly separated.
The Agent needs to understand when it should use the Postgres tool and what information it is trying to retrieve.
The Postgres tool description needs to explain how the database is structured and how the SQL must be written.
So I would not put the full SQL-generation instructions inside the Agent’s main system prompt unless the model is consistently failing to use the tool correctly. That creates duplicate instructions, uses more tokens and can sometimes make the Agent less predictable.
Inside the Postgres Query field you can use:
{{ $fromAI(
'sql_query',
'Generate the complete read-only PostgreSQL query required to answer the user request.',
'string'
) }}
Then put the database-specific information inside the tool description, for example:
Use this tool to retrieve data from the news_articles table.
The event_understanding and institutional_understanding columns use the JSONB data type.
Use PostgreSQL JSONB operators when accessing nested properties.
For a top-level text value, use:
event_understanding-\">>'sentiment'
For deeper nested values, use:
event_understanding-\">>'analysis'-\">>'sentiment'
Only generate SELECT queries.
Never generate INSERT, UPDATE, DELETE, DROP, ALTER or TRUNCATE queries.
Use only the tables and columns described here.
One important distinction is that Define automatically by the model does not magically inspect or understand your nested JSONB schema.
It can generate a query that accesses nested values, but only when the model knows:
- the table name,
- the JSONB column name,
- the available nested keys,
- their expected value types,
- and preferably one or two valid query examples.
Without that information, the model may invent keys or produce SQL that is syntactically valid but does not match your actual data.
Also, be careful with the operator being used:
json_column-\">>'nested_object'
returns JSON or JSONB, while:
json_column-\">>'nested_value'
returns the value as text.
For example:
SELECT *
FROM news_articles
WHERE event_understanding-\">>'sentiment' = 'Positive';
For a deeper structure:
SELECT *
FROM news_articles
WHERE event_understanding-\">>'classification'-\">>'sentiment' = 'Positive';
So your additional Agent instruction was not necessarily wrong, but it is probably unnecessary if the Agent already understands that it should call the Postgres tool.
I would keep the main Agent prompt focused on behaviour and put the SQL schema, nested JSON paths and restrictions inside the Postgres tool description.
And because the model is generating the complete query, I would strongly restrict the database credentials to read-only access. Prompt instructions are useful, but they are not a security boundary.