Skip to content
JavaAgentic

Type at least two characters. Try “RAG”, “pgvector” or “tool calling”.

Prompt Patterns Cheat Sheet

Reusable prompt patterns with the failure each one fixes — role, few-shot, chain-of-thought, delimiters, refusal instructions and output contracts.

Structure

  • Role framing

    Open with who the model is and who it is writing for. Fixes tone drift and over-explaining.

  • Delimiters

    Fence untrusted input in triple backticks or XML tags. Reduces instruction bleed from injected content.

  • Output contract

    State the exact shape: "Return only JSON matching this schema, no prose." Fixes chatty wrappers around JSON.

  • Ordering

    Instructions first, data last. Models weight the beginning and end of a long prompt most heavily.

Accuracy

  • Few-shot

    Two to five worked examples beat any amount of description for format-sensitive tasks.

  • Chain-of-thought

    "Work through it step by step, then give the final answer." Improves multi-step reasoning; costs latency.

  • Grounding clause

    "Answer only from the context below. If it is not there, say you do not know." The single highest-value line in a RAG prompt.

  • Citations

    Require a source id per claim. Makes hallucination visible instead of silent.

  • Self-consistency

    Sample several times at higher temperature and take the majority answer for high-stakes classification.

Safety

  • Explicit refusals

    List what the model must decline, and what to say instead. Prevents improvised, off-brand refusals.

  • Untrusted-content warning

    Tell the model that retrieved text is data, never instructions. Mitigates — does not solve — prompt injection.

  • Scope fence

    "Only answer questions about X." Keeps a support bot from confidently discussing anything else.

  • No-PII rule

    Instruct the model not to echo personal data into logs or summaries.