Text2SQL System Prompt Updater
Use this skill when the task is to improve the SQL generation system prompt in:
packages/text2sql/src/lib/agents/sql.agent.ts
packages/context/src/lib/fragments/*
This skill is about prompt quality and policy design, not CLI ergonomics.
Goal
Increase SQL correctness by adding or refining general prompt policies that improve behavior across many cases.
Non-Negotiables
- Do not hardcode benchmark-specific hints in the prompt.
- Do not include table names, literal values, or question text from one failing case as examples.
- Do not change model-under-test unless explicitly requested.
- Do not remove existing product behavior or options.
- Prefer durable rules over one-off fixes.
- Prefer fragment-based policy updates over persona text edits.
When Prompt Changes Are Appropriate
Prompt changes are appropriate when failures come from model behavior patterns, such as:
- false
unanswerable decisions despite mappable schema
- unnecessary transformations (
strftime, substr, derived columns)
- weak predicate choices (for example
IS NOT NULL instead of explicit value)
- dropped join constraints or weaker query shape
- aggregation shape mismatches (
WHERE vs GROUP BY/HAVING, superlative handling)
- unnecessary
DISTINCT
- schema spelling normalization that breaks exact columns
When Prompt Changes Are Not Appropriate
Do not patch prompt first when failures are caused by:
- broken eval or scorer infrastructure
- adapter validation bugs
- parser/runtime failures unrelated to query reasoning
- dataset or expected-output issues
Fix those at the correct layer first.
Iteration Workflow
- Baseline and scope
- Work in fixed-size ranges for large datasets and keep reruns scoped to previously failed records.
- Capture pass/fail counts and representative failures.
- Cluster failures by behavior
- Group failures into reusable categories (mapping, aggregation, joins, literals, transformations, set ops).
- Avoid case-by-case prompt wording.
- Write policy-level prompt updates
- Add concise rules that define behavior, not examples.
- Keep precedence clear: schema grounding first, then query-shape preferences, then fallback/error behavior.
- Patch only prompt policy text
- Update reusable fragment policies
packages/context fragment primitives.
- Avoid adding dataset-specific examples.
- Rebuild and validate
- Re-run the same scoped range.
- Then rerun failed-only within that range until stable.
- Once a range stabilizes, move to the next range.
- Regression check
- Re-test previously fixed ranges to confirm no backslide.
Prompt Writing Rules
- Use explicit policy language: “Prefer…”, “Only when…”, “Do not…”.
- Keep rules short, concrete, and non-overlapping.
- Encode semantic flexibility generally (aliasing, lexical normalization), never with benchmark literals.
- Encode minimality: avoid extra columns, extra transforms, and speculative projections unless required.
- Encode strict schema fidelity: never hallucinate tables/columns, preserve exact column spelling.
Recommended Policy Patterns
- Best-effort mapping before unanswerable:
- “Do not return unanswerable if intent can be derived via filtering, joining, grouping, or set operations over existing schema.”
- Aggregation correctness:
- “Use GROUP BY + HAVING for per-entity aggregate constraints.”
- “For most/least by entity, prefer ORDER BY aggregate + LIMIT 1.”
- Set semantics:
- “Use INTERSECT for shared members across both criteria.”
- “Use UNION for either-of criteria when combining sets.”
- Predicate precision:
- “Use exact equality for explicit values unless pattern matching is requested.”
- Minimal SQL:
- “Avoid date parsing/substrings/derived projections unless explicitly requested or schema requires it.”
Anti-Patterns
- benchmark-specific mapping examples in system prompt
- overfit lexical shortcuts tied to one dataset
- contradictory rules that cause output oscillation
- forcing wrong joins instead of schema-grounded best effort
- using persona text as the default location for every new behavior rule
Definition of Done
- Target range reaches stable pass goals after failed-only reruns.
- No new regressions in previously passing ranges.
- Prompt diff is generalizable and free of benchmark-specific wording.
- A short summary maps each new rule to a failure category it addresses.
1---2name: text2sql-system-prompt-updater3description: Update the Text2SQL system prompt in a generalizable, non-overfit way using failure-pattern driven evaluation loops. Use when SQL generation quality regresses or specific failure classes repeat.4---56# Text2SQL System Prompt Updater78Use this skill when the task is to improve the SQL generation system prompt in:910- `packages/text2sql/src/lib/agents/sql.agent.ts`11- `packages/context/src/lib/fragments/*`1213This skill is about prompt quality and policy design, not CLI ergonomics.1415## Goal1617Increase SQL correctness by adding or refining general prompt policies that improve behavior across many cases.1819## Non-Negotiables2021- Do not hardcode benchmark-specific hints in the prompt.22- Do not include table names, literal values, or question text from one failing case as examples.23- Do not change model-under-test unless explicitly requested.24- Do not remove existing product behavior or options.25- Prefer durable rules over one-off fixes.26- Prefer fragment-based policy updates over persona text edits.2728## When Prompt Changes Are Appropriate2930Prompt changes are appropriate when failures come from model behavior patterns, such as:3132- false `unanswerable` decisions despite mappable schema33- unnecessary transformations (`strftime`, `substr`, derived columns)34- weak predicate choices (for example `IS NOT NULL` instead of explicit value)35- dropped join constraints or weaker query shape36- aggregation shape mismatches (`WHERE` vs `GROUP BY/HAVING`, superlative handling)37- unnecessary `DISTINCT`38- schema spelling normalization that breaks exact columns3940## When Prompt Changes Are Not Appropriate4142Do not patch prompt first when failures are caused by:4344- broken eval or scorer infrastructure45- adapter validation bugs46- parser/runtime failures unrelated to query reasoning47- dataset or expected-output issues4849Fix those at the correct layer first.5051## Iteration Workflow52531. Baseline and scope5455- Work in fixed-size ranges for large datasets and keep reruns scoped to previously failed records.56- Capture pass/fail counts and representative failures.57582. Cluster failures by behavior5960- Group failures into reusable categories (mapping, aggregation, joins, literals, transformations, set ops).61- Avoid case-by-case prompt wording.62633. Write policy-level prompt updates6465- Add concise rules that define behavior, not examples.66- Keep precedence clear: schema grounding first, then query-shape preferences, then fallback/error behavior.67684. Patch only prompt policy text6970- Update reusable fragment policies `packages/context` fragment primitives.71- Avoid adding dataset-specific examples.72735. Rebuild and validate7475- Re-run the same scoped range.76- Then rerun failed-only within that range until stable.77- Once a range stabilizes, move to the next range.78796. Regression check8081- Re-test previously fixed ranges to confirm no backslide.8283## Prompt Writing Rules8485- Use explicit policy language: “Prefer…”, “Only when…”, “Do not…”.86- Keep rules short, concrete, and non-overlapping.87- Encode semantic flexibility generally (aliasing, lexical normalization), never with benchmark literals.88- Encode minimality: avoid extra columns, extra transforms, and speculative projections unless required.89- Encode strict schema fidelity: never hallucinate tables/columns, preserve exact column spelling.9091## Recommended Policy Patterns9293- Best-effort mapping before unanswerable:94 - “Do not return unanswerable if intent can be derived via filtering, joining, grouping, or set operations over existing schema.”95- Aggregation correctness:96 - “Use GROUP BY + HAVING for per-entity aggregate constraints.”97 - “For most/least by entity, prefer ORDER BY aggregate + LIMIT 1.”98- Set semantics:99 - “Use INTERSECT for shared members across both criteria.”100 - “Use UNION for either-of criteria when combining sets.”101- Predicate precision:102 - “Use exact equality for explicit values unless pattern matching is requested.”103- Minimal SQL:104 - “Avoid date parsing/substrings/derived projections unless explicitly requested or schema requires it.”105106## Anti-Patterns107108- benchmark-specific mapping examples in system prompt109- overfit lexical shortcuts tied to one dataset110- contradictory rules that cause output oscillation111- forcing wrong joins instead of schema-grounded best effort112- using persona text as the default location for every new behavior rule113114## Definition of Done115116- Target range reaches stable pass goals after failed-only reruns.117- No new regressions in previously passing ranges.118- Prompt diff is generalizable and free of benchmark-specific wording.119- A short summary maps each new rule to a failure category it addresses.