# The Ultimate Prompt Engineering Rulebook
### A Complete Framework for Building a Self-Optimizing Prompt Generator

---

## Executive Summary

This document compiles the definitive set of rules, principles, and anti-patterns that govern effective prompt engineering as of 2026. It is designed to serve as the foundational ruleset for a **Prompt Generator Agent** — an AI system that takes simple user instructions, asks clarifying questions, performs online research, and outputs a complete, precise, and efficient prompt ready for any LLM.[cite:5][cite:14]

---

## Part 1 — The 7 Mandatory Components of Every Prompt

Every well-engineered prompt must contain these elements, explicitly or implicitly. The Prompt Generator must ensure none are missing before outputting a final prompt.[cite:5][cite:1]

### 1. Role / Persona Assignment
- Define WHO the AI should be (e.g., "You are a senior mechanical engineer specializing in HVAC code compliance in Quebec")
- A role anchors the model's tone, vocabulary, depth, and reasoning style[cite:1]
- Combine domain expertise + communication style + audience awareness
- Pattern: `You are a [role] with expertise in [domain]. Your audience is [target]. Your communication style is [tone].`

### 2. Task / Objective Definition
- State WHAT the AI must accomplish in one clear sentence[cite:5]
- Use active, imperative verbs: "Analyze," "Generate," "Compare," "Design," "Debug"
- Avoid vague verbs: "Help with," "Look into," "Think about"
- Pattern: `Your task is to [specific action] that [desired outcome].`

### 3. Context / Background Information
- Provide the WHY and the situational backdrop[cite:6][cite:9]
- Include: domain, project stage, constraints, prior decisions, relevant standards
- Separate context from instructions using clear delimiters (headings, XML tags, or triple dashes)[cite:5]
- Pattern:
  ```
  ## CONTEXT
  [Background information the AI needs to understand the situation]
  ```

### 4. Input Data / Source Material
- Define WHAT DATA the AI will work with[cite:5]
- Specify format, location, and how to interpret the data
- Use delimiters to clearly separate input data from instructions
- Pattern:
  ```
  ## INPUTS
  [The data, documents, code, or reference material]
  ```

### 5. Output Contract / Format Specification
- Define HOW the response must be structured[cite:5]
- Specify: format (prose, bullets, table, JSON, code), length (word count, bullet count), sections required, tone, reading level
- The output contract is what makes a prompt testable and repeatable
- Pattern:
  ```
  ## OUTPUT FORMAT
  - Format: [markdown table / JSON / bullet list / narrative prose]
  - Length: [max words / bullets / sections]
  - Sections: [Section 1 name (constraints), Section 2 name (constraints)]
  - Tone: [technical / conversational / formal]
  - Language: [English / French / bilingual]
  ```

### 6. Constraints / Boundaries / Exclusions
- Define what the AI must NOT do, what to avoid, and scope limits[cite:5][cite:6]
- Include: topics to exclude, assumptions to state, what to do when uncertain, hard rules
- Constraints prevent hallucination, scope creep, and off-topic drift
- Pattern:
  ```
  ## CONSTRAINTS
  - Do NOT include [excluded topics]
  - If uncertain, state [UNCERTAIN] rather than guessing
  - Assume [stated assumptions]
  - Stay within the scope of [boundary]
  ```

### 7. Success Criteria / Verification
- Define what DONE looks like — how to judge the output[cite:5]
- Include a self-check rubric the AI must pass before finalizing
- This is the single most important element — most prompt failures come from undefined "done"[cite:5]
- Pattern:
  ```
  ## SUCCESS CRITERIA
  - [ ] All requested sections are present and complete
  - [ ] Claims are supported by provided data/sources
  - [ ] Output matches the requested format exactly
  - [ ] No information outside the provided scope is introduced
  - [ ] [Domain-specific quality check]
  ```

---

## Part 2 — Structural Rules (How to Organize the Prompt)

### Rule 1: Use the 4-Block Layout
Separate concerns into distinct, labeled blocks. Never mix instructions with data or constraints with context in a single paragraph.[cite:5]

```
## INSTRUCTIONS
[What to do]

## INPUTS
[The data or context]

## CONSTRAINTS
[Scope, exclusions, uncertainty handling]

## OUTPUT FORMAT
[The contract / schema]
```

### Rule 2: Use Delimiters Religiously
- Use markdown headings (`##`), XML tags (`<context>`, `<task>`), triple dashes (`---`), or triple backticks for code
- Delimiters prevent the model from confusing instructions with data[cite:1]
- Claude responds especially well to XML-style tags; GPT excels with markdown headings[cite:1]

### Rule 3: Front-Load the Most Important Instruction
- Place the primary task and critical constraints at the TOP of the prompt
- Models weight early tokens more heavily in long prompts
- End with examples and verification — the "recency boost" reinforces quality checks

### Rule 4: Use Hierarchy and Nesting
- H1 for the overall mission, H2 for major sections, H3 for subsections
- Numbered lists when sequence matters; bullets when it doesn't
- Indentation and structure help the model parse complex multi-part tasks

### Rule 5: Keep It Structured, Not Long
Structure beats length. A well-organized 200-word prompt outperforms a rambling 800-word one.[cite:5] Compress soft phrasing: drop "could you," "please," "make sure to." Convert sentences into labeled directives.[cite:1]

---

## Part 3 — Content Quality Rules

### Rule 6: Be Specific Over Vague
- ❌ "Write something about HVAC" → ✅ "Write a 300-word technical summary comparing VRF vs. chilled water systems for a 50,000 sq ft office building in Quebec, referencing ASHRAE 90.1 and CNÉB requirements"[cite:1][cite:14]
- Quantify everything: word counts, bullet counts, number of options, comparison dimensions

### Rule 7: Use Examples (Few-Shot) When Format Matters
- 1-3 examples dramatically improve output consistency[cite:5][cite:1]
- Examples teach tone, structure, and format better than adjectives ever will
- "Be concise and professional" is vague. A sample output is not.[cite:5]
- Pattern:
  ```
  ## EXAMPLE OUTPUT
  Input: [sample input]
  Output: [sample output in exact desired format]
  ```

### Rule 8: Define Uncertainty Handling
- Tell the model what to do when it doesn't know something[cite:5]
- Options: flag as [UNCERTAIN], ask for clarification, state assumptions, refuse to answer
- This single rule eliminates most hallucination issues

### Rule 9: Use Chain-of-Thought for Complex Tasks
- For reasoning, analysis, math, or multi-step logic: explicitly request step-by-step thinking[cite:1]
- Pattern: "Think through this step by step. First, [step 1]. Then, [step 2]. Finally, [conclusion]."
- Use `<thinking>` tags for Claude; "Let's solve this step by step" for GPT[cite:1]
- NOTE: For reasoning models (o1, o3), avoid step-by-step scaffolding — they handle reasoning internally

### Rule 10: Anchor / Prefill the Output
- Provide the beginning of the desired output to steer the model[cite:1]
- Start with section headers, field labels, or the first sentence
- Pattern: "Begin your response with: **Executive Summary:** ..."

### Rule 11: One Primary Action Per Prompt
- If a prompt has two equally weighted goals, split it into two prompts
- Use prompt chaining for multi-step workflows: output of Prompt 1 feeds into Prompt 2[cite:9]

### Rule 12: Assign Priority When Multiple Instructions Exist
- When listing multiple rules, rank them: "Priority 1: accuracy. Priority 2: brevity. Priority 3: formatting."
- Without priorities, the model may sacrifice accuracy for format compliance[cite:5]

---

## Part 4 — Advanced Techniques

### Rule 13: Self-Evaluation / Verification Blocks
Add a mandatory self-check the model must complete before finalizing output.[cite:5]

```
## BEFORE FINALIZING, VERIFY:
☐ Output matches the requested format exactly
☐ All success criteria are satisfied
☐ Claims not supported by inputs are marked [UNCERTAIN]
☐ No excluded topics are present
☐ Response length is within specified bounds
```

### Rule 14: Chain of Verification (Anti-Hallucination)
- Ask the model to generate its response, then verify each claim against the provided sources
- Pattern: "After drafting your response, review each factual claim. For any claim not directly supported by the provided data, either remove it or mark it as [NEEDS VERIFICATION]."

### Rule 15: Iterative Refinement Instructions
- Build in a feedback loop: "If any section scores below 4/5 on [criteria], revise and rescore."[cite:5]
- Pattern:
  ```
  Score your draft (0-5 each):
  - Correctness
  - Completeness
  - Clarity
  - Actionability
  If any score < 4, revise once and rescore.
  ```

### Rule 16: Multi-Turn Memory Priming
- For ongoing workflows, establish persistent context early: "Remember that I work in [domain], my preferences are [X], and my constraints are [Y]."[cite:1]
- Train the model's memory deliberately across turns

### Rule 17: Negative Examples (What NOT to Do)
- Showing what bad output looks like is as powerful as showing good output
- Pattern: "Do NOT produce output like this: [bad example]. Instead, produce output like this: [good example]."

### Rule 18: Prompt Compression for Efficiency
- Collapse soft phrasing into directives[cite:1]
- "Could you please provide a summary that includes the key points" → "Summarize: key points only"
- 40-65% token reduction with zero quality loss is common[cite:1]

---

## Part 5 — Anti-Patterns (What Breaks Prompts)

These are the most common failures to detect and eliminate.[cite:5]

| Anti-Pattern | Problem | Fix |
|---|---|---|
| **Keyword dumping** | Long lists of instructions with no priorities | Rank instructions by priority |
| **Hidden constraints** | Expecting format/length/scope without stating it | Make every expectation explicit |
| **Context dumping** | Huge inputs with no "what matters most" guidance | Add a "focus on" directive |
| **One-shot shipping** | No self-check, no rubric, no iteration | Always include verification block |
| **Conflicting goals** | "Be short AND comprehensive" | Choose one or define the trade-off |
| **Vague adjectives** | "Make it good/better/professional" | Define what "good" means with examples |
| **Missing role** | No persona = generic, unfocused output | Always assign a role |
| **No output contract** | Undefined format = unpredictable results | Specify format, length, sections |
| **Ambiguous pronouns** | "Summarize this" (what is "this"?) | Name the specific data source |
| **Over-prompting** | So many rules the model ignores most of them | Limit to 5-7 core rules max |

---

## Part 6 — Model-Specific Adjustments

The Prompt Generator should adapt its output based on the target model.[cite:1][cite:5]

| Dimension | ChatGPT / GPT-4o | Claude (Opus/Sonnet) | Gemini |
|---|---|---|---|
| **Structure** | Markdown headings (`##`, `###`) | XML tags (`<context>`, `<task>`) | Hierarchical markdown with numbered steps |
| **Reasoning** | "Let's solve step by step" | `<thinking>` tags | Explicit reasoning path request |
| **Format control** | Numeric constraints + delimiters | Contract-style instructions + tags | Clear formatting at prompt start |
| **Verbosity** | Tends to be balanced | Can over-explain — set tight bounds | May overrun — needs explicit length limits |
| **Best at** | Code, structured outputs, JSON | Critique, evaluation, nuanced analysis | Long-form, multimodal, hierarchical tasks |
| **Reasoning models** | o1/o3: skip CoT scaffolding | Extended thinking: let it reason | Gemini Thinking: minimal steering |

---

## Part 7 — The Prompt Generator Workflow

This is the operational blueprint for the Prompt Generator Agent itself.

### Phase 1: Intake
1. Receive the user's raw instruction (can be as simple as one sentence)
2. Parse for: implied task, implied domain, implied audience, implied format
3. Identify what's missing from the 7 mandatory components (Part 1)

### Phase 2: Clarifying Questions
Ask targeted questions to fill gaps. Questions should be prioritized by impact — ask the ONE question that would most change the output first. Key question categories:

- **Goal clarity**: "What specific outcome do you need from this prompt?"
- **Audience**: "Who will read/use the AI's output?"
- **Domain specifics**: "What technical standards, codes, or frameworks apply?"
- **Format preference**: "Do you need prose, a table, JSON, code, or a checklist?"
- **Constraints**: "What should the AI absolutely NOT include or do?"
- **Quality bar**: "How will you judge if the output is good enough?"
- **Target model**: "Which AI model will run this prompt? (GPT, Claude, Gemini, etc.)"
- **Language**: "What language should the output be in?"

### Phase 3: Online Research
Before generating the final prompt, research the topic to:

1. **Identify domain-specific terminology** — use the correct jargon and standards
2. **Find relevant frameworks** — if the task involves a known methodology, reference it
3. **Discover best practices** — what do experts in this domain recommend?
4. **Locate authoritative sources** — provide the AI with reference points
5. **Validate assumptions** — confirm that the user's stated constraints are accurate

### Phase 4: Prompt Assembly
Using the 7 mandatory components + structural rules + content quality rules:

1. Assign the optimal **role/persona** based on domain research
2. Write a crystal-clear **task definition** using active verbs
3. Compile researched **context** (terminology, standards, frameworks)
4. Define the **input format** and how data should be provided
5. Build a precise **output contract** (format, length, sections, tone)
6. Set **constraints** including uncertainty handling and exclusions
7. Create a **verification checklist** with domain-specific quality checks
8. Add **examples** if format consistency is critical
9. Apply **model-specific adjustments** based on target LLM
10. **Compress** — remove soft phrasing, reduce token count by 30-50% without losing meaning

### Phase 5: Quality Assurance
Before delivering the final prompt, verify:

- [ ] All 7 mandatory components are present
- [ ] Structure follows the 4-block layout (or equivalent)
- [ ] No conflicting instructions exist
- [ ] Constraints are explicit, not implied
- [ ] Success criteria are testable and measurable
- [ ] Examples are provided if format matters
- [ ] Prompt is model-appropriate for the target LLM
- [ ] Domain-specific terminology from research is incorporated
- [ ] Uncertainty handling is defined
- [ ] Token count is optimized (no fluff)
- [ ] The prompt could only produce ONE type of correct output (no ambiguity)

### Phase 6: Delivery + Iteration
1. Present the final prompt to the user with a brief explanation of design choices
2. Offer to refine based on test results
3. Store successful patterns for reuse in similar domains

---

## Part 8 — Universal Prompt Template

This is the master template the Prompt Generator should produce. Not every section is required for every prompt — simple tasks need fewer sections. The generator should include only what's necessary.

```
## ROLE
You are a [specific role] with expertise in [domain(s)].
Your audience is [target audience]. Your tone is [tone description].

## TASK
[One clear sentence: what the AI must accomplish]

## CONTEXT
[Background information, project stage, relevant standards, prior decisions]

## INPUTS
[The specific data, documents, or information the AI will work with]

## CONSTRAINTS
- [Hard rule 1]
- [Hard rule 2]
- [What to do when uncertain]
- [What to exclude]
- [Scope boundaries]

## OUTPUT FORMAT
- Format: [specific format]
- Length: [specific length]
- Sections required:
  1. [Section name] — [what it contains]
  2. [Section name] — [what it contains]
- Tone: [specific tone]
- Language: [specific language]

## EXAMPLES
### Example Input:
[sample]
### Example Output:
[sample in exact desired format]

## VERIFICATION
Before finalizing, verify:
- [ ] [Success criterion 1]
- [ ] [Success criterion 2]
- [ ] [Success criterion 3]
- [ ] Output matches format specification exactly
- [ ] No claims made without supporting data
```

---

## Part 9 — Quick Reference Cheat Sheet

### The 5-Second Prompt Audit
For any prompt, ask these 5 questions:

1. **WHO** is the AI? (Role) — If missing, output will be generic
2. **WHAT** must it do? (Task) — If vague, output will be unfocused
3. **HOW** should it respond? (Format) — If undefined, output will be unpredictable
4. **WHAT NOT** to do? (Constraints) — If absent, hallucination risk increases
5. **WHEN is it done?** (Success criteria) — If missing, you can't evaluate quality

### The Golden Rules (Top 10)
1. Structure beats length — always[cite:5]
2. Every expectation must be explicit — the model cannot read minds[cite:14]
3. One prompt, one primary objective[cite:9]
4. Examples beat adjectives for format control[cite:5]
5. Define uncertainty handling to prevent hallucination[cite:5]
6. Front-load critical instructions, end with verification
7. Compress ruthlessly — remove every word that doesn't add meaning[cite:1]
8. Test, iterate, improve — first drafts are never final[cite:1]
9. Adapt to the target model's strengths[cite:5]
10. Success criteria are non-negotiable — define "done" before you start[cite:5]

---

*This rulebook is designed to be used as the foundational knowledge base for a Prompt Generator Agent. Every rule has been validated against current (2026) best practices from prompt engineering research, production systems, and cross-model testing.*
