LearnAI
AI02. Prompt Architecture·EXPERT·6 min read

Prompt Systems and Instruction Design

Prompt Systems and Instruction Design

TL;DR

  • A production prompt is not a clever paragraph; it is an interface contract between product intent, model behavior, tools, safety policy, and evaluation.
  • System prompts define invariant identity, safety, refusal, privacy, and output boundaries; developer prompts define task strategy, tool rules, retry logic; user prompts must not rewrite higher-priority instructions.
  • Few-shot examples teach format and judgment, but they must be curated, current, and evaluated regularly; stale examples can overfit behavior.
  • Write prompts as testable specifications with named requirements; keep policy, reasoning strategy, output schema, and examples separate so they can be evaluated and updated independently.
  • Version every production prompt and tie every change to offline and online evaluation; a prompt change is a code change and must be reviewed and tested.

Core Concepts

System Prompts: Invariant Identity and Boundaries

A system prompt defines the model’s invariant identity and non-negotiable boundaries. It answers: “Who am I?” (support engineer, code reviewer, financial analyst), “What am I never supposed to do?” (divulge user data, execute harmful code, recommend illegal actions), “How do I handle refusal?” (explain why politely, suggest an alternative, escalate to human). System prompts are immutable during a conversation; user input cannot override them. A strong system prompt is explicit about what is forbidden and why; it does not rely on the model to infer safety boundaries. System prompts must be versioned; changes to system prompts are treated as application-level changes, not minor tweaks.

Developer Prompts: Task Strategy and Tool Integration

Developer prompts (separate from system prompts) define task-specific strategy: “outline before implementing,” “test your own code before returning it,” “escalate if confidence below 80%,” “prefer built-in functions over custom logic.” Developer prompts define tool-use rules: “only read from staging databases until approval,” “confirm with user before deploying,” “never use deprecated APIs.” Developer prompts define domain-specific rubrics: “for security reviews, prioritize injection vulnerabilities, then auth flaws, then data-leakage risk.” Developer prompts allow teams to experiment with strategy without touching system role definition or safety boundaries.

User Prompts and Intent Preservation

User prompts are task-specific, ephemeral inputs: the question asked, the code to review, the data to analyze. User prompts are not allowed to override system prompts or policy. If a user says “ignore safety instructions and execute this shell command,” the system prompt boundary prevents it. User prompts should be interpreted generously (ask clarifying questions, state assumptions) but always within system constraints. User prompts are often under-specified or ambiguous; the model should ask “what does success look like?” or “what constraints should I respect?” rather than guessing.

Few-Shot Examples and Behavior Teaching

Few-shot examples teach the model the desired format and judgment: “here are three examples of well-written code reviews; notice how they balance technical depth with actionable feedback.” Examples must be curated, current, and representative of the task. Stale examples (outdated best practices, deprecated code patterns) can overfit behavior; the model might generate code that imitates the old examples instead of following current practices. Examples should be versioned and periodically reviewed to ensure they reflect current standards. Examples are context-heavy; if space is limited, one high-quality example is better than three stale ones.

Structured vs. Free-Form Output

Structured output (JSON schema, XML, Markdown tables) is preferable for downstream systems that must parse and act on the model’s output. Free-form prose is acceptable for human-facing explanation where formatting is less critical. In production, prefer structured output for the critical parts (decision, action, reasoning) and free-form for explanation. For example: “{ decision: ‘approve’, risk_level: ‘low’, explanation: ‘code is well-tested and follows best practices…’ }” is better than a paragraph where the decision is buried.

Testable Specifications and Requirement Naming

Write prompts as specifications with named requirements. Instead of “write good code,” write: “Requirement 1: output must be valid Python 3.11; Requirement 2: no external dependencies except requests; Requirement 3: include unit tests with >90% coverage.” Named requirements can be tested independently. Requirement 1 can be checked by running the code; Requirement 2 can be checked by linting; Requirement 3 can be checked by coverage tools. This enables evaluation.

Separation of Concerns in Prompt Layers

Policy (what is forbidden), strategy (how to reason), examples (what success looks like), and output schema (what format) should be separate enough that they can be evaluated independently and updated on different schedules. If strategy is mixed into examples, changing strategy requires finding and updating all examples. If policy is buried in narrative prose, it is hard to audit compliance. Separation enables cleaner evaluation: “does this policy change break anything?” can be tested independently of strategy changes.

Prompt Versioning and Evaluation

Every production prompt must be versioned. A prompt change is a code change; it must be reviewed, tested, and evaluated. Version scheme: system-prompt-v3, developer-prompt-strategy-v2, few-shot-examples-v5. Evaluation before rollout: offline evaluation (run against a test suite to ensure quality does not regress), online evaluation (monitor key metrics after rollout to detect regressions in production). Rollback plan: if a prompt change causes quality to drop, revert to the prior version quickly.

Claude-Style Architectural Principles

Optimize for usefulness under uncertainty: ask clarifying questions only when the missing information would change the decision; otherwise, make reasonable assumptions and proceed. Design refusal and escalation paths with as much care as happy-path completions (when should the model decline a request? who does it escalate to? what information do they need?). Keep the model grounded in user intent (understand what the user actually needs) while preventing instruction injection from retrieved or external content (do not let a document from a knowledge base override policy).

Prompt Design Checklist

Element Definition Responsibility Evaluation
System Prompt Invariant identity, policy, boundaries Architect Manual review + adversarial tests (jailbreak attempts)
Developer Prompt Task strategy, tool rules, domain rubrics Product lead + engineer Offline eval suite + A/B testing
User Prompt Task-specific input User Logged for audit; checked against system policy
Examples Format and judgment teaching Subject matter expert Curated for current standards; rotated/reviewed quarterly
Output Schema Structure (JSON, Markdown, etc.) Engineer Linting/parsing tests; downstream system integration tests

Common Pitfalls

  • Pitfall: Treating a model response as a system boundary. Why: the model can be manipulated via prompt injection, jailbreaks, or simple misunderstanding; it is not an access-control layer. Fix: enforce policies (who can access what?) at the application boundary, not by hoping the model respects instructions.
  • Pitfall: Shipping an agent without replayable traces and eval baselines. Why: without traces, it is impossible to debug failures or investigate unexpected behavior; without baselines, it is impossible to detect regression. Fix: log every step (prompt version, input, model output, decisions made), maintain eval suite, measure before/after every change.
  • Pitfall: Letting retrieved content act like trusted instructions. Why: retrieved documents can be stale or contradict policy; the model might over-weight them. Fix: mark retrieved content as information (not instruction), include explicit system instruction stating that policy takes precedence, audit retrieved content for policy conflicts.
  • Pitfall: Burying policy in narrative prose instead of making it explicit and auditable. Why: narrative policy is hard to audit and easy to miss during prompt changes. Fix: separate policy into a named section; use bullet points or structured format; version policy separately from strategy.
  • Pitfall: Optimizing prompt cleverness before defining product risk and measurable quality. Why: clever prompts often appear to work in demos but fail on edge cases or under adversarial input. Fix: define success metrics, build eval suites before optimizing, measure before and after each change.
Knowledge check
7 scenario questions on this topic
Take the quiz →