Using DSPy to evaluate and improve Datasette Agent's SQL system prompts
Summary
A project utilizes the DSPy framework to evaluate and refine the core production system prompts for Datasette Agent's read-only SQL question answerer. The methodology involves DSPy agents invoking Datasette Agent's actual tool implementations and prompts against a live in-process Datasette. Rigorous evaluation is conducted using a gold-standard, auto-generated dataset and custom metrics. Initial research, prompted by an AIE keynote and executed via Claude Fable 5 using GPT 4.1 mini and nano, identified a critical issue: the prompt's schema listing, which only provided table names, led to column-name guessing (e.g., "page_count", "o.order_id") and error-retry loops. This problem was compounded by advice to "don't call describe_table if you already have the information." The proposed solution is to either include column names directly in the prompt's schema listing or modify the problematic advice.
Key takeaway
For Prompt Engineers developing SQL-generating agents, you should integrate frameworks like DSPy for systematic prompt evaluation. This approach helps uncover subtle issues, such as incomplete schema information or counterproductive instructions, that lead to execution errors. Specifically, ensure your database schema prompts include full column details and carefully review any advice that might restrict the agent's ability to gather necessary information, preventing costly error-retry loops and improving query accuracy.
Key insights
The DSPy framework effectively identifies and resolves prompt engineering issues in SQL agent systems.
Principles
- Schema listings in prompts need full detail.
- Overly restrictive prompt advice can backfire.
- Automated prompt evaluation reveals subtle flaws.
Method
Use DSPy agents to invoke tools against a live system. Evaluate with auto-generated gold-standard datasets and custom metrics.
In practice
- Test SQL agent prompts with DSPy.
- Include column names in database schema prompts.
- Re-evaluate restrictive prompt instructions.
Topics
- DSPy
- Datasette Agent
- Prompt Engineering
- SQL Generation
- LLM Evaluation
- Claude Fable 5
Code references
Best for: Prompt Engineer, Machine Learning Engineer, AI Engineer
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Simon Willison's Weblog.