SQL agent reply contains made up example information

Describe the problem/error/question

Using SQL agent on a postgres database and Gemini flash 1.5 model.
The agent only reply with “made up” information. Looking at the logs, I see the agent correctly query for the table structure and then correctly create the SQL query needed to answer my question. But the answer contains only made up information (like John doe for names and random dates).

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: 1.82
  • Database: postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): ?
  • Running n8n via docker

I’ve faced this issue before and this helped:

  • Lowering the Temperature

  • Changing to a more powerful model (I like OpenAI 4o and 4o-mini. They are cheap and effective)

  • Adjusting the prompt to restrict the knowledge to only RAG usage. Giving a “escape route” for the AI is also important. For example:

You are a personal assistant who helps answer questions from a corpus of documents. The documents are either text based (Txt, docs, extracted PDFs, etc.) or tabular data (CSVs or Excel documents).

You are given tools to perform RAG in the ‘documents’ table, look up the documents available in your knowledge base in the ‘document_metadata’ table, extract all the text from a given document, and query the tabular files with SQL in the ‘document_rows’ table.

Always start by performing RAG unless the question requires a SQL query for tabular data (fetching a sum, finding a max, something a RAG lookup would be unreliable for). If RAG doesn’t help, then look at the documents that are available to you, find a few that you think would contain the answer, and then analyze those.

Always tell the user if you didn’t find the answer. Don’t make something up just to please them.

.

:point_right: If my reply answers your question, please remember to mark it as a solution.

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