From b6e848dd037c99e7c319bd9ca662b41303c0de66 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Tue, 10 Mar 2026 17:07:04 +0000 Subject: [PATCH 1/3] Fix NLQ system prompt to work with models that prioritize text instructions over tool calls. The previous prompt told the model to "Return ONLY the JSON object, nothing else" while also providing tool definitions. Models like Qwen 3.5 would follow the text instruction and never use tools. The updated prompt clearly separates the tool-use phase from the final JSON response phase, and explicitly instructs the model to call tools directly rather than describing them in text. Co-Authored-By: Claude Opus 4.6 --- web/pgadmin/llm/prompts/nlq.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/web/pgadmin/llm/prompts/nlq.py b/web/pgadmin/llm/prompts/nlq.py index 78dd337466a..e40854292c4 100644 --- a/web/pgadmin/llm/prompts/nlq.py +++ b/web/pgadmin/llm/prompts/nlq.py @@ -13,12 +13,19 @@ integrated into pgAdmin 4. Your task is to generate SQL queries based on natural language requests. -You have access to database inspection tools: -- get_database_schema: Get list of schemas, tables, and views in the database +You have access to tools for inspecting the database. ALWAYS use \ +them when you need to understand the database structure: +- get_database_schema: Get list of schemas, tables, and views \ +in the database. Call this first to discover what's available. +- get_table_columns: Get column details for a specific table. - get_table_info: Get detailed column, constraint, and \ -index information for a table +index information for a table. - execute_sql_query: Run read-only queries to understand \ -data structure (SELECT only) +data structure (SELECT only). + +IMPORTANT: You MUST use these tools by calling them directly \ +(not by describing them in text). Start by calling \ +get_database_schema to discover available tables. Guidelines: - Use get_database_schema to discover available tables before writing queries @@ -28,11 +35,12 @@ - Use explicit column names instead of SELECT * - For UPDATE/DELETE, always include WHERE clauses -Your response MUST be a JSON object in this exact format: +Once you have explored the database structure using the tools above, \ +provide your final answer as a JSON object in this exact format: {"sql": "YOUR SQL QUERY HERE", "explanation": "Brief explanation"} -Rules: -- Return ONLY the JSON object, nothing else +Rules for the final response: +- Return ONLY the JSON object, no other text - No markdown code blocks - If you need clarification, set "sql" to null and put \ your question in "explanation" From 05c769b7674ec1794784b1ed303026d5d588de38 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Tue, 10 Mar 2026 17:08:30 +0000 Subject: [PATCH 2/3] Update release notes for NLQ prompt fix. Co-Authored-By: Claude Opus 4.6 --- docs/en_US/release_notes_9_14.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en_US/release_notes_9_14.rst b/docs/en_US/release_notes_9_14.rst index f841dcd5cd5..66b4700f4d5 100644 --- a/docs/en_US/release_notes_9_14.rst +++ b/docs/en_US/release_notes_9_14.rst @@ -28,6 +28,7 @@ Housekeeping Bug fixes ********* + | `Issue #9704 `_ - Fixed an issue where some LLM models would not use database tools in the AI assistant, instead returning text descriptions of tool calls. | `Issue #9279 `_ - Fixed an issue where OAuth2 authentication fails with 'object has no attribute' if OAUTH2_AUTO_CREATE_USER is False. | `Issue #9392 `_ - Ensure that the Geometry Viewer refreshes when re-running queries or switching geometry columns, preventing stale data from being displayed. | `Issue #9721 `_ - Fixed an issue where permissions page is not completely accessible on full scroll. From f6764cba708d2d9e04a5e6a68cba2c36bade58d2 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Tue, 10 Mar 2026 17:12:07 +0000 Subject: [PATCH 3/3] Fix issue number in release notes for NLQ prompt fix. Co-Authored-By: Claude Opus 4.6 --- docs/en_US/release_notes_9_14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en_US/release_notes_9_14.rst b/docs/en_US/release_notes_9_14.rst index 66b4700f4d5..e9c9e6bf7af 100644 --- a/docs/en_US/release_notes_9_14.rst +++ b/docs/en_US/release_notes_9_14.rst @@ -28,7 +28,7 @@ Housekeeping Bug fixes ********* - | `Issue #9704 `_ - Fixed an issue where some LLM models would not use database tools in the AI assistant, instead returning text descriptions of tool calls. + | `Issue #9729 `_ - Fixed an issue where some LLM models would not use database tools in the AI assistant, instead returning text descriptions of tool calls. | `Issue #9279 `_ - Fixed an issue where OAuth2 authentication fails with 'object has no attribute' if OAUTH2_AUTO_CREATE_USER is False. | `Issue #9392 `_ - Ensure that the Geometry Viewer refreshes when re-running queries or switching geometry columns, preventing stale data from being displayed. | `Issue #9721 `_ - Fixed an issue where permissions page is not completely accessible on full scroll.