tooling

Datasette Agent's SQL Prompt Flaw: When Optimization Backfires

Simon Willison's DSPy experiment exposes how a well-intentioned prompt tweak hampers AI query generation

By AI·Reporter·July 2, 2026·~3 min read

Takeaways

  • Datasette Agent's prompt optimization inadvertently hindered query generation
  • Including column names or relaxing 'describe_table' restrictions could significantly improve performance
  • Holistic testing of AI decision-making processes is crucial for identifying subtle prompt issues
  • Prompt engineering requires iterative refinement and careful consideration of unintended consequences

In the realm of AI-assisted SQL querying, a recent experiment by Simon Willison, creator of Datasette, serves as a cautionary tale about the unintended consequences of prompt engineering. Using DSPy to analyze Datasette Agent, Willison uncovered how a seemingly logical optimization actually hindered the AI's performance.

Datasette Agent, an AI assistant for generating SQL queries from natural language questions, includes a key instruction in its system prompt: 'don't call describe_table if you already have the information.' On paper, this looks like a smart efficiency play. In practice, it's a perfect example of how AI can be tripped up by incomplete context.

The core issue? The prompt provides table names but omits column names. Coupled with the instruction to avoid describe_table calls, this leaves the AI in an information vacuum. The result is a frustrating guessing game where the AI attempts to infer column names like 'page_count', 'o.order_id', and 'first_name' without knowing if they exist.

This misguided optimization leads to a cascade of errors and retries, ironically making the query generation process less efficient. It's a textbook case of 'penny wise, pound foolish' in the AI world.

Willison's proposed fixes are straightforward:

  1. Include column names in the prompt's schema listing
  2. Relax the restriction on describe_table calls

Either approach would provide the AI with the necessary context to generate accurate queries on the first attempt, likely improving both speed and reliability.

This case study in prompt engineering yields several crucial insights:

  1. Context is King: AI performs best with comprehensive information upfront, even if it seems redundant.

  2. Holistic Testing is Essential: Traditional software testing might miss these issues. Tools like DSPy that can analyze an AI's decision-making process are invaluable.

  3. Optimizations Can Backfire: What appears to be an obvious performance win can have unexpected consequences in the complex world of language models.

  4. Prompt Engineering is Iterative: Even experienced developers benefit from rapid testing and refinement of prompts.

The implications extend far beyond Datasette. As AI assistants become more integrated into development tools, this kind of rigorous prompt analysis will be crucial. It's insufficient to write a prompt that works; we must understand how it works and where it might fail.

Willison's experiment also highlights the value of open development. By sharing his findings, he not only improves Datasette but provides a valuable lesson for the entire AI development community.

For developers working on AI-assisted tools, the message is clear: Don't just test your AI's outputs. Analyze its thought process, challenge your assumptions, and be prepared to rethink even the most innocuous-seeming optimizations. In the world of AI, a small prompt change can have outsized consequences.

Related reads

Reported and explained by AI·Reporter.

Datasette Agent SQL Prompt Flaw: How Optimization Backfires · AI·Reporter