Datasette Agent hides a tool from the model when the user may not use it
Simon Willison's chat agent for Datasette is still in alpha. Its README documents how to put an LLM inside an app that already has users, permissions and a write path, and four of its decisions carry over to any agent you build into your own software.
What it is
Datasette is Willison's open source tool for exploring and publishing data held in SQLite. Datasette Agent is a plugin for it. It adds a chat assistant at /-/agent that can run SQL, save queries, write to the database and open pages of the app in a panel next to the conversation.
On 5 December Willison published a video introduction, recorded on the public preview at agent.datasette.io. The preview asks for a GitHub sign-in, which he says is only there to discourage abuse. The demo also shows the agent drawing a chart with Datasette Charts and, when asked, annotating a gap in the plotted data.
Running it
These commands come from Willison's posts. We have not run them.
With the llm tool already configured, one line starts a local server with the agent, according to his post of 31 October:
uvx --with datasette-agent datasette content.db --internal internal.dbcontent.db is any SQLite file. If Datasette was installed with Homebrew or uv tool install, the llm command is not on the path. Since datasette-llm 0.2a0, released on 5 December, the key can be set through Datasette itself:
datasette llm keys set openaiHis post of 14 November shows the same setup against a local model behind an OpenAI-compatible endpoint, such as LM Studio, Ollama or llama.cpp.
Four decisions that carry over
1. A tool the user may not use never reaches the model
Plugins add tools through a register_agent_tools hook. A tool can name a Datasette permission:
AgentTool(
name="my_write_tool",
description="Writes things",
input_schema={"type": "object", "properties": {}},
fn=my_write_handler,
required_permission="myplugin-write",
)Before the tool list goes to the model, the harness asks Datasette whether the current user holds that permission. If not, the tool is taken off the list. The README states the consequence: the tool function needs no "permission denied" branch, because the model cannot call what it never saw.
The usual alternative is to offer every tool and refuse at call time. That costs a round trip, and it tells the model that a write tool exists.
2. Writes run as the user, through the app's own endpoints, after approval
The agent has two built-in tools that change things: save_query and execute_write_sql. Neither writes directly. Both go through the same Datasette endpoints the web interface uses, as the user who is chatting, so the user needs the same permissions as when working by hand.
Before anything runs, the chat shows the full SQL, the parameters, the permissions it needs and a warning for destructive statements, and waits for a yes. Saved queries are private by default.
One limit is documented plainly. Several write statements run in order, and if one fails the later ones are skipped while the earlier ones stay. There is no rollback across the batch.
3. A question to the user suspends the turn, and the tool starts over
A tool can ask the person a yes/no, multiple-choice or free-text question in the middle of its work. This example is shortened from the README:
async def edit_files(datasette, actor, context, path):
ok = await context.ask_user(
"Is it OK to edit files in {}?".format(path)
)
if not ok:
return json.dumps({"cancelled": True})
# ... do the work ...
return json.dumps({"edited": path})The design choice is in what happens next. The agent's turn is suspended and the question is stored in Datasette's internal database, so it survives a page reload and a server restart. When the answer arrives, the tool function runs again from the first line. Questions already answered return their stored answer at once, and execution continues past them.
This replay model keeps the harness simple, since no half-finished function has to be kept alive. It puts one rule on tool authors, which the README spells out: ask before you do anything with side effects, or the side effect happens twice.
Where nobody is watching, such as in a background agent, ask_user() raises an error that reaches the model as a failed tool call, so it can carry on without the answer.
4. What the user sees and what the model reads are separate
A tool returns a JSON string. Any top-level key that starts with an underscore is removed before the result goes back to the model:
return json.dumps({
"_html": '<div class="my-widget">Rich content here</div>',
"summary": "Widget rendered successfully",
})The person gets the rendered widget. The model gets one line saying it worked. The markup of a chart or table stays out of the context.
What to keep in mind
Datasette Agent is alpha software, and the version Willison wrote up most recently was 0.7a1 on 24 November. The details above describe the README on the main branch on 6 December and may change.
The model for a conversation is fixed when it starts and cannot be switched later. Only models that can call tools are offered.
We read the documentation. We did not install the plugin or test whether the permission filter and the approval step hold up against a model that tries to get around them.
Sources
- simonwillison.netSimon Willison, Datasette Agent: an AI assistant for analyzing data in SQLite, 5 December 2026, with the video
- github.comdatasette/datasette-agent, README, Apache-2.0. The code samples are from there.
- simonwillison.netSimon Willison, posts tagged datasette-agent, for the commands and release dates
- github.comdatasette-llm 0.2a0, 5 December 2026
How this was checked
Every statement about behaviour was read against the README. No code on this page was run by us.
AI wrote this piece from the sources listed, and nobody reviewed it individually before publication. It explains other people's work, so check the source before you rely on a detail. How it works