Skip to main content

Module prompt

Module prompt 

Source
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:

  1. 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.
  2. 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 put cache_control: ephemeral on.

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§

CacheControl
cache_control payload — currently always ephemeral. The Anthropic API also accepts {"type": "ephemeral", "ttl": "1h"}; we expose that via [CacheTtl] in crate::config.
SystemBlock
One block of an Anthropic system array.
UserMessage
One element of an Anthropic messages array. We only ever send role: "user"ask() is stateless / one-shot.

Constants§

SYSTEM_RULES
The system prompt’s first block — load-bearing instructions.

Functions§

build_system
Build the system array for an Anthropic request.