Home/ Part XIII — Expert Mode: Systems, Agents, and Automation/39. Prompt Engineering for Experts (The Real Stuff)/39.1 Hierarchical prompts: global rules → module rules → task rules

39.1 Hierarchical prompts: global rules → module rules → task rules

Overview and links for this section of the guide.

The Cascade Strategy

If you put 50 rules in one system prompt, the model will ignore half of them (the "Lost in the Middle" phenomenon).

Split your context:

  1. Global Rules: "Always use TypeScript. Always use 2 spaces indentation." (Applied to everything).
  2. Module Rules: "In `/auth`, use the `User` class, never `db.users` directly." (Applied only when editing auth files).
  3. Task Rules: "For this specific bug, ensure you handle the null case." (Applied only now).

Dynamically assemble the prompt: `System = Global + Module + Task`.

Example Hierarchy

Global:
- No `console.log` in production.
- Use `zod` for validation.

Module (Payment):
- NEVER log credit card numbers.
- Retry Stripe calls 3 times.

Task:
- Fix the retry logic in `charge.ts`.

Where to go next