SKILL: draft-prompt
Purpose
Build and refine the draft prompt that produces a complete court-ready legal document in a single LLM call. v5.1 uses free-text drafting — the LLM outputs the entire document (not section-keyed JSON, not gap-fill). Exemplar-guided, LKB-informed.
When to Use
- Building or modifying
prompts/draft_prompt.py
- Debugging why draft quality is low
- Tuning exemplars or context injection
- Adapting prompt for a new cause type
- Optimizing prompt token count
Architecture Context (v5.1 — what's running)
Single LLM call produces the complete document. No templates, no section keys, no gap-fill markers.
intake_classify -> rag -> enrichment -> draft_freetext_node -> 4 gates -> review
Model: glm-5:cloud with reasoning=ON, temperature=0.7, ~30-50s
System Prompt Structure
build_draft_freetext_system_prompt(doc_type, cause_type) builds:
- Role — "senior Indian litigation lawyer, 25 years practice"
- Exemplar — loaded via
load_exemplar(doc_type) (~1,500 tokens)
- LKB quality rules — Q1-Q10, COA rules, relief rules (from LKB entry)
- Substantive rules — R1-R16 (anti-hallucination, citation, formatting)
- Output instruction — "Write the COMPLETE document as it would appear when filed in court"
Key instruction: plain text output, not JSON, not markdown code blocks.
User Prompt Structure
build_draft_freetext_user_prompt(...) includes (in order):
- User request (facts FIRST — lost-in-middle principle)
- Extracted facts summary from intake
- Parties context
- Evidence context
- Limitation context — from
_build_limitation_context()
- Verified provisions — from
_build_verified_provisions_context()
- LKB brief — from
_build_lkb_brief_context() (acts, limitation, terminology)
- RAG context — from
_build_rag_context() (top chunks, deduped)
Context Builders (in draft_single_call.py)
| Builder |
What it provides |
_build_limitation_context() |
Limitation article, period, description. Handles article == "NONE" |
_build_verified_provisions_context() |
List of verified statutory provisions from enrichment |
_build_rag_context() |
Top RAG chunks from Qdrant, deduped, scored |
_build_lkb_brief_context() |
Primary acts, limitation summary, terminology, anti-hallucination instruction |
_build_procedural_requirements_context() |
Court rules, procedural requirements from LKB |
LKB Brief Builder
_build_lkb_brief_context() feeds verified legal knowledge to the draft LLM:
- Primary acts with sections
- Alternative acts
- Limitation article + period (or "NO LIMITATION APPLIES" when article=NONE)
- Terminology mapping (conditional, resolved at runtime)
- Anti-hallucination instruction: "Use RAG text, not training memory"
Exemplars
Structural exemplars per cause type in exemplars/ directory (~1,500 tokens each):
- Show document structure, section order, heading style
- Use generic placeholders, not specific facts
- Guide LLM on Indian legal drafting conventions
To add a new exemplar:
- Create file in
exemplars/ matching cause type name
load_exemplar(doc_type) auto-discovers by naming convention
- Exemplar included in system prompt
Draft Node Flow (draft_single_call.py)
draft_freetext_node(state):
- Build system prompt (exemplar + LKB + rules)
- Build user prompt (facts + context)
- Single LLM call -> raw text output
- Strip markdown fences if present (defensive)
- Clean encoding artifacts
- Append advocate block if absent
- Collect placeholders
- Wrap in
DraftArtifact -> draft.draft_artifacts[0]
- Route to
evidence_anchoring gate
Key Files
| File |
What |
prompts/draft_prompt.py |
System/user prompt builders + exemplar loading |
nodes/draft_single_call.py |
draft_freetext_node + all context builders |
exemplars/ |
Structural exemplars per cause type |
lkb/civil.py |
LKB entries feeding the brief |
Rules
- User facts go FIRST in user prompt (lost-in-middle: LLMs attend best to start/end)
- Only cite VERIFIED PROVISIONS — enrichment provides the list
- Exemplar guides structure, LKB guides substance
- Plain text output — no JSON, no markdown code blocks
- Max 5 system instruction rules (Few-Shot > Exhaustive Rules)
- Strip markdown fences defensively (LLM sometimes wraps)
- Handle
limitation.article == "NONE" explicitly
Anti-Patterns
- Do NOT use JSON section-key output format
- Do NOT add must_include checklists in prompt
- Do NOT add per-scenario instructions (if partition do X, if money do Y)
- Do NOT dump all RAG chunks raw — use context builders to filter/score
- Do NOT constrain legal reasoning ("must cite Section 65")
- Do NOT hardcode legal content in Python — LKB + RAG + exemplar handles it
- Do NOT exceed prompt budget unnecessarily — compression matters for speed
1---2name: section-drafter-prompt3description: SKILL: draft-prompt4---5# SKILL: draft-prompt67## Purpose8Build and refine the draft prompt that produces a complete court-ready legal document in a single LLM call. v5.1 uses free-text drafting — the LLM outputs the entire document (not section-keyed JSON, not gap-fill). Exemplar-guided, LKB-informed.910## When to Use11- Building or modifying `prompts/draft_prompt.py`12- Debugging why draft quality is low13- Tuning exemplars or context injection14- Adapting prompt for a new cause type15- Optimizing prompt token count1617## Architecture Context (v5.1 — what's running)1819Single LLM call produces the complete document. No templates, no section keys, no gap-fill markers.2021```22intake_classify -> rag -> enrichment -> draft_freetext_node -> 4 gates -> review23```2425Model: **glm-5:cloud** with reasoning=ON, temperature=0.7, ~30-50s2627---2829## System Prompt Structure3031`build_draft_freetext_system_prompt(doc_type, cause_type)` builds:32331. **Role** — "senior Indian litigation lawyer, 25 years practice"342. **Exemplar** — loaded via `load_exemplar(doc_type)` (~1,500 tokens)353. **LKB quality rules** — Q1-Q10, COA rules, relief rules (from LKB entry)364. **Substantive rules** — R1-R16 (anti-hallucination, citation, formatting)375. **Output instruction** — "Write the COMPLETE document as it would appear when filed in court"3839Key instruction: plain text output, not JSON, not markdown code blocks.4041---4243## User Prompt Structure4445`build_draft_freetext_user_prompt(...)` includes (in order):46471. **User request** (facts FIRST — lost-in-middle principle)482. **Extracted facts summary** from intake493. **Parties context**504. **Evidence context**515. **Limitation context** — from `_build_limitation_context()`526. **Verified provisions** — from `_build_verified_provisions_context()`537. **LKB brief** — from `_build_lkb_brief_context()` (acts, limitation, terminology)548. **RAG context** — from `_build_rag_context()` (top chunks, deduped)5556---5758## Context Builders (in draft_single_call.py)5960| Builder | What it provides |61|---------|-----------------|62| `_build_limitation_context()` | Limitation article, period, description. Handles `article == "NONE"` |63| `_build_verified_provisions_context()` | List of verified statutory provisions from enrichment |64| `_build_rag_context()` | Top RAG chunks from Qdrant, deduped, scored |65| `_build_lkb_brief_context()` | Primary acts, limitation summary, terminology, anti-hallucination instruction |66| `_build_procedural_requirements_context()` | Court rules, procedural requirements from LKB |6768---6970## LKB Brief Builder7172`_build_lkb_brief_context()` feeds verified legal knowledge to the draft LLM:73- Primary acts with sections74- Alternative acts75- Limitation article + period (or "NO LIMITATION APPLIES" when article=NONE)76- Terminology mapping (conditional, resolved at runtime)77- Anti-hallucination instruction: "Use RAG text, not training memory"7879---8081## Exemplars8283Structural exemplars per cause type in `exemplars/` directory (~1,500 tokens each):84- Show document structure, section order, heading style85- Use generic placeholders, not specific facts86- Guide LLM on Indian legal drafting conventions8788To add a new exemplar:891. Create file in `exemplars/` matching cause type name902. `load_exemplar(doc_type)` auto-discovers by naming convention913. Exemplar included in system prompt9293---9495## Draft Node Flow (draft_single_call.py)9697`draft_freetext_node(state)`:981. Build system prompt (exemplar + LKB + rules)992. Build user prompt (facts + context)1003. Single LLM call -> raw text output1014. Strip markdown fences if present (defensive)1025. Clean encoding artifacts1036. Append advocate block if absent1047. Collect placeholders1058. Wrap in `DraftArtifact` -> `draft.draft_artifacts[0]`1069. Route to `evidence_anchoring` gate107108---109110## Key Files111112| File | What |113|------|------|114| `prompts/draft_prompt.py` | System/user prompt builders + exemplar loading |115| `nodes/draft_single_call.py` | `draft_freetext_node` + all context builders |116| `exemplars/` | Structural exemplars per cause type |117| `lkb/civil.py` | LKB entries feeding the brief |118119---120121## Rules122- User facts go FIRST in user prompt (lost-in-middle: LLMs attend best to start/end)123- Only cite VERIFIED PROVISIONS — enrichment provides the list124- Exemplar guides structure, LKB guides substance125- Plain text output — no JSON, no markdown code blocks126- Max 5 system instruction rules (Few-Shot > Exhaustive Rules)127- Strip markdown fences defensively (LLM sometimes wraps)128- Handle `limitation.article == "NONE"` explicitly129130## Anti-Patterns131- Do NOT use JSON section-key output format132- Do NOT add must_include checklists in prompt133- Do NOT add per-scenario instructions (if partition do X, if money do Y)134- Do NOT dump all RAG chunks raw — use context builders to filter/score135- Do NOT constrain legal reasoning ("must cite Section 65")136- Do NOT hardcode legal content in Python — LKB + RAG + exemplar handles it137- Do NOT exceed prompt budget unnecessarily — compression matters for speed