LLMs & GenAI

Prompt Engineering That Works

Systematic techniques for structuring LLM prompts to maximize accuracy, formatting reliability, and reasoning.

🟢 beginner5 min readllmpractical
Prompt Engineering is the practice of designing input prompt structures to guide Large Language Model behavior effectively. Key techniques include assigning System Personas, providing explicit Delimiters, setting structural Output Constraints (JSON / Markdown), using Negative Constraints, and employing Few-Shot Exemplars. Systematic prompt engineering turns unpredictable LLM responses into reliable, production-ready outputs.

What is Systematic Prompt Engineering?

Prompt Engineering is often misunderstood as guessing magical words to get good AI responses.

In production engineering, Prompt Engineering is the discipline of structuring input text to guide LLM attention mechanisms reliably toward desired outputs:

┌──────────────────────────┬──────────────────────────┬──────────────────────────┐
│ 1. SYSTEM PERSONA        │ 2. EXPLICIT DELIMITERS   │ 3. FEW SHOT EXEMPLARS    │
├──────────────────────────┼──────────────────────────┼──────────────────────────┤
│ Defines role, boundaries,│ Uses <context> tags or   │ Demonstrates exact input │
│ and output constraints.  │ triple backticks to mark │ to output examples.      │
│ Anchors global tone.     │ input boundary zones.    │ Anchors schema format!   │
└──────────────────────────┴──────────────────────────┴──────────────────────────┘

Core Building Blocks of Production Prompts

  ┌─────────────────────────────────────────────────────────────┐
  │ SYSTEM PERSONA & ROLE DEFINITION                            │
  │ "You are an expert SQL engineer. Return ONLY valid SQL."    │
  ├─────────────────────────────────────────────────────────────┤
  │ CONSTRAINTS & FORMAT RULES                                  │
  │ "- Output JSON format only. Zero conversational intro text."  │
  ├─────────────────────────────────────────────────────────────┤
  │ INPUT CONTEXT (Marked with XML Delimiters)                  │
  │ "<database_schema> ... </database_schema>"                  │
  ├─────────────────────────────────────────────────────────────┤
  │ FEW SHOT EXEMPLARS                                          │
  │ "Example 1: Input -> Output"                                │
  ├─────────────────────────────────────────────────────────────┤
  │ USER QUERY & GENERATION TRIGGER                             │
  │ "Query: Find top 5 users \n SQL:"                           │
  └─────────────────────────────────────────────────────────────┘

Top 5 Battle-Tested Prompt Techniques

1. Assign a Clear System Persona

Directing the model to adopt a specific role primes internal memory representations:

2. Use Structural XML Delimiters

Demarcate input boundaries using explicit tags:

Summarize the following document:
<document>
[Raw Document Text Here]
</document>

This prevents Prompt Injection where malicious text inside the document attempts to hijack system instructions.

3. Add Negative Constraints

Explicitly specify what the model must NOT do:

4. Leverage Few-Shot Exemplars

Showing is better than telling. Provide 2 or 3 examples demonstrating input-to-output mappings to lock in formatting schemas.

5. Position Instructions at Context Boundaries

Due to Lost-in-the-Middle attention degradation:

Say this out loud

Systematic prompt engineering uses role personas, structural XML delimiters, negative constraints, and few shot exemplars to guide LLM outputs. Placing core instructions at context boundaries and providing concrete input to output examples anchors model attention, producing reliable production ready responses.

Followups to expect

  1. What is System Prompt Drift? When long conversation histories dilute the influence of initial system prompt instructions. Fix by appending key constraints to the user turn or using System Prompt Fine-Tuning.
  2. What is Structured Output / Constrained Decoding? Using tools like Outlines or Instructor to enforce JSON schema constraints at the Softmax logit level during decoding, guaranteeing 100 percent valid schema output.

Check yourself

Question 1 of 3

Why are explicit XML or Markdown delimiters (like <context>...</context> or

More in LLMs & GenAI

See all →
Pretraining → SFT → RLHF5 minFine-Tune vs RAG vs Prompt: Choosing5 minRetrieval-Augmented Generation5 min