Skip to content

Update instructions to avoid common local LLM errors - #14

Merged
simonw merged 1 commit into
datasette:mainfrom
blech:fix/agent-tool-prompt
Jun 10, 2026
Merged

simonw merged 1 commit into
datasette:mainfrom
blech:fix/agent-tool-prompt

Conversation

@blech

@blech blech commented May 22, 2026

Copy link
Copy Markdown
Contributor

Locally hosted, smaller, LLMs are likely to make two errors
when calling tools: using 'kwargs' as a literal argument name,
pushing real arguments too deep into the call, and using 'query'
for the argument to the 'sql_query' tool, rather than 'sql'.

This patch updates the prompt to try to avoid both of these
mistakes.

Locally hosted, smaller, LLMs are likely to make two errors
when calling tools: using 'kwargs' as a literal argument name,
pushing real arguments too deep into the call, and using 'query'
for the argument to the 'sql_query' tool, rather than 'sql'.

This patch updates the prompt to try to avoid both of these
mistakes.
@blech

blech commented May 22, 2026

Copy link
Copy Markdown
Contributor Author

Addresses #12.

@blech
blech marked this pull request as ready for review May 22, 2026 17:22
@simonw

simonw commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The kwargs thing is really weird, I wonder where that comes from.

@simonw

simonw commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

I'm going to land this now, and file a new issue for building a small eval suite to help test the prompt against more models.

@simonw
simonw merged commit dfadf72 into datasette:main Jun 10, 2026
5 checks passed
simonw added a commit that referenced this pull request Jun 10, 2026
simonw added a commit that referenced this pull request Nov 1, 2026
The list of databases and tables in the system prompt changed whenever a
table was created, invalidating any provider prompt cache for the whole
conversation history, and it had no size limit. The prompt is now the same
for every actor and schema, and models call list_databases_and_tables.

That tool is now the main way to find tables, so it has to cope with large
instances. Output over the 10,000 character limit was cut by halving the
list of databases, silently dropping whole databases. It now returns every
database with a table_count and a note to call the new list_tables tool,
which takes a required database argument. If a single database is still
too long, list_tables returns as many names as fit and suggests searching
sqlite_master.

sql_query with display=user hid the rows from the model, so a COUNT(*)
came back as row_count 1 and Qwen 3.5 4B could report that as the answer.
Single-row results now go to the model as well as the user. Results with
more rows include a note saying how to read the values.

sql_query with display=both now includes num_rows_shown_to_user when there
is more than one row. The model's copy of the rows can be cut to fit the
output limit while the user's table is not, so Qwen 3.5 4B was reporting
250 rows when the user could see 1,000.

Two sql_query output fields are renamed so that smaller models are less
likely to misread them: row_count is now num_rows_shown_to_user, and
truncated is now has_more_rows. Saved conversations keep the old names,
and nothing reads them back.

Other system prompt changes:

- Say that the databases are SQLite
- Remove the warning about wrapping arguments in a kwargs key, added in
  #14. That appears to have been caused by llm-ollama showing models a
  phantom kwargs parameter, which it fixed in 9739550 and c8a6fd6 by
  honoring input_schema

Tested against Qwen 3.5 4B using llm-lmstudio.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants