Expand description
Prompt construction — turn a schema dump + a natural-language question into the request shape Anthropic expects.
§Structure (matters for prompt caching)
system is a list of two text blocks:
- Rules — frozen instructions about what dialect of SQL to emit, what JSON shape to wrap the answer in, and what to do when the schema doesn’t support the question. Byte-stable across every call, regardless of which DB is connected.
- Schema dump — the output of [
crate::schema::dump_schema]. Stable for a given DB, changes when the DB’s schema changes. This is the block we putcache_control: ephemeralon.
The user’s question goes in messages[0] (always volatile, never
cached).
Render order is tools → system → messages, so a cache_control
marker on the last system block caches the rules + the schema
together. We don’t currently send any tools.
§What we ask the model to produce
Strict JSON: {"sql": "...", "explanation": "..."}. Asking for
JSON in the prompt (rather than via the API’s structured-output
parameter) keeps this crate compatible with non-Anthropic
providers we’ll add later — Ollama models without structured-
output support still need to work.
Structs§
- Cache
Control cache_controlpayload — currently alwaysephemeral. The Anthropic API also accepts{"type": "ephemeral", "ttl": "1h"}; we expose that via [CacheTtl] incrate::config.- System
Block - One block of an Anthropic
systemarray. - User
Message - One element of an Anthropic
messagesarray. We only ever sendrole: "user"—ask()is stateless / one-shot.
Constants§
- SYSTEM_
RULES - The system prompt’s first block — load-bearing instructions.
Functions§
- build_
system - Build the
systemarray for an Anthropic request.