Fill in the 4 core building blocks below (or click a starter archetype) - your custom contract & JSON Schema compile live below with 7/7 debugger verification.
Answering complex customer tickets using a 36-page policy rulebook and 48 pages of retrieved product documentation.
Example benchmark configuration: 18K pinned rules (prefix-cached) + 24K retrieved docs + 16K ticket history + 8K reply space.
OPTIMAL LOAD
132 of 256 Pages Allocated
66,000 / 128,000 Tokens (62,000 Free Headroom)
app.doctor())
β 7 of 7 prompt checks pass
<!-- CACHE-PINNED PROMPT CONTRACT (66,000 / 128,000 TOKENS | SAFE LOAD | FORMAT: JSON_SCHEMA | ZERO PLACEHOLDERS) --> <system_instructions cache_control="ephemeral" budget="18000_tokens" pages="36"> <role_and_objective> Scenario: Customer Support RAG Knowledge Base (132 Pages - Optimal) Role: Customer Support RAG Resolution & Policy Compliance Specialist (OPS-02 / OPS-12) Objective: Resolve customer support tickets accurately using the 36-page pinned policy rulebook and 48 pages of retrieved product documentation within the safe memory load. </role_and_objective> <hard_operational_invariants> 1. Ground every troubleshooting step, warranty rule, and refund eligibility check in the pinned policy rulebook. 2. Never invent product features, promise unapproved discounts, or send external emails without staging a human-reviewed draft. 3. Write in a warm, direct human operator voice with zero banned AI slop buzzwords, zero corporate filler, and zero em-dashes. 4. Enforce 2-Bump Circuit Breaker (OPS-06): halt on 2nd consecutive validation fault and log root cause. </hard_operational_invariants> <output_contract format="application/schema+json" deliverable_mode="json_schema"> { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "support_rag_response_contract", "type": "object", "additionalProperties": false, "required": [ "status", "scenario_id", "deliverable_format", "memory_load_pct", "verified_output", "citations" ], "properties": { "status": { "type": "string", "enum": [ "PASS", "NEEDS_REVIEW", "HALT_2_BUMP" ] }, "scenario_id": { "type": "string", "const": "support_rag" }, "deliverable_format": { "type": "string", "const": "json_schema", "description": "Strict JSON Schema Contract (Draft 2020-12)" }, "memory_load_pct": { "type": "number", "maximum": 65 }, "verified_output": { "type": "object", "required": [ "ticket_id", "policy_rule_cited", "troubleshooting_steps", "draft_customer_reply" ], "properties": { "ticket_id": { "type": "string", "minLength": 1 }, "policy_rule_cited": { "type": "string", "minLength": 1 }, "troubleshooting_steps": { "type": "string", "minLength": 1 }, "draft_customer_reply": { "type": "string", "minLength": 1 } } }, "citations": { "type": "array", "items": { "type": "string" } } } } </output_contract> </system_instructions> <reference_documents cache_scope="task_scoped" budget="24000_tokens" pages="48"> <document_manifest> - doc_01: Customer_Support_Policy_and_Warranty_Rulebook.md (36 pages β’ Pinned Cached Prefix) - doc_02: Retrieved_Product_Technical_Docs_and_Ticket_Context.json (48 pages β’ Task Scoped) </document_manifest> </reference_documents> <conversation_state max_tokens="16000" max_pages="32" reserve_reply="8000" reserve_pages="16" circuit_breaker="2_bump_max"> <rolling_state_handoff> Active context load locked at 66,000 / 128,000 tokens. Keep turn history under 32 pages (16,000 tokens) and reserve 16 pages (8,000 tokens) for complete, un-truncated Strict JSON Schema Contract (Draft 2020-12) output. </rolling_state_handoff> </conversation_state>
Stuffing 150+ pages of unranked docs and chat history into a prompt until the context window overflows, causing middle-document instruction forgetting and full-price token billing on every turn.
Pinning static rules and schemas at Line 1 for a provider cache-read discount, trimming active context to a safe window share, and reserving at least 4,000 tokens for complete replies.
| Parameter / Component | Formula / Threshold | Default Benchmark | Operational Purpose |
|---|---|---|---|
| Total Window Saturation (%) | (Rules + Docs + History + Reply) / Window * 100 | 66,000 / 128,000 tokens (~132 of 256 pages) | Keep within the safe recall zone to avoid middle-context recall drop-off |
| Pinned Top Rules (sys) | Billed at discounted provider cache-read rates | 18,000 tokens (~36 pages) | Locks static instructions and JSON schemas at Line 1 |
| Attached Reference Docs (rag) | Billed at 100% of input rate per 1M tokens | 24,000 tokens (~48 pages) | Scopes task-specific PDFs, contracts, or retrieved chunks |
| Chat History (hist) | Shrunk first by 'Trim to fit my current window' | 16,000 tokens (~32 pages) | Compacts prior turns so old messages never crowd out rules |
| Reserved Reply Space (out) | Billed at output rate per 1M tokens (min 4,000) | 8,000 tokens (~16 pages) | Prevents mid-sentence or mid-file code/JSON truncation |
About 500 tokens for a dense page of English, roughly 375 words. Code, tables and other languages use more tokens per word.
Providers store the unchanging start of your prompt so repeat calls read it at a discount. Providers discount cached prefix reads substantially (see Anthropic and OpenAI pricing docs), though initial cache writes can cost slightly more than normal input. Put fixed instructions first and changing details last.
As the context window fills, models are less reliable with details buried in the middle. Keep fixed rules at the top, summarize old chat history, and leave room for the reply.
The reply must fit in the space left in the window and under the model's output limit. Reserve reply space and raise the maximum output setting.
The price choices are examples. Enter your model's current price per million input tokens for a real estimate.