From how_to_make_sql_queries.ipynb in the cookbook. A minimal, schema-aware text-to-SQL prompt that constrains the model to output only the SQL.
Here is the schema for a database:
{schema}
Given this schema, can you output a SQL query to answer the following question? Only output the SQL query and nothing else.
QuestiOn: {query}
A more reliable extended version, from the capabilities/text_to_sql guide, wraps the schema in XML tags and constrains the output:
You are an AI assistant that converts natural language queries into SQL.
Given the following SQL database schema:
<schema>
{schema}
</schema>
Convert the following natural language query into SQL:
<query>
{query}
</query>
Provide only the SQL query in your response, enclosed within <sql> tags.
Source: https://github.com/anthropics/anthropic-cookbook/blob/main/misc/how_to_make_sql_queries.ipynb