Prompt Engineering — Cheat Sheet

Tags: prompt-engineering, llm, system-prompts, few-shot, context-window, evaluation

Level: intermediate

TL;DR: Best practices, structured design patterns, and evaluation strategies for reliable model steering and deterministic outputs.

Key concepts

System prompts define persistent operational boundaries, role identity, and behavioral constraints.

Few-shot prompting provides in-context demonstration pairs to anchor expected input-output schema.

Chain-of-Thought (CoT) decomposes complex multi-step reasoning before producing final answers.

Delimiters isolate untrusted input from instructions to prevent prompt injection and ambiguity.

Negative constraints perform worse than explicit instructions describing target behavior.

Output format enforcement works best when coupled with schema validation like JSON Schema.

Context placement matters: critical constraints are best retained at prompt start or prompt end.

Temperature and sampling parameters directly influence adherence to strict structural instructions.

Automated evaluation requires deterministic ground-truth assertions or programmatic LLM-as-a-judge rubrics.

Typical questions and ready answers

Q: How do you guarantee consistent JSON outputs across varied runtime requests?R: I enforce schema via structured output flags, specify schema explicitly inside system instructions, provide few-shot JSON examples, and validate output programmatically with Pydantic or Zod.

Q: How do you mitigate prompt injection in pipelines consuming user-provided text?R: I wrap user input in distinct delimiters, apply input sanitization, explicitly state that enclosed text cannot alter system rules, and evaluate inputs with dedicated guard models.

Q: When do you pick fine-tuning over prompt engineering?R: I start with prompt engineering for rapid iteration; I switch to fine-tuning only when latency, context window costs, or domain-specific style adaptations cannot be met by few-shot prompting.

Pitfalls and common mistakes

Relying on vague modifiers like "concise" instead of specifying concrete length or token limits.

Overloading context with redundant instructions that dilute model attention over critical rules.

Mixing user-supplied input into system prompt templates without structural boundaries.

Neglecting evaluation datasets before deploying prompt revisions to production pipelines.

Snippets and commands

<system_instructions>
You are an expert data extraction engine. Extract entities according to schema.
Rules:
1. Return valid JSON only. Do not include markdown codeblocks or commentary.
2. If an attribute is missing, set its value to null.
</system_instructions>

<input_data>
Customer reached out via phone on 2026-10-24 regarding invoice INV-4091.
</input_data>

<output_schema>
{"date": "YYYY-MM-DD", "channel": "string", "reference_id": "string"}
</output_schema>

Python

```from pydantic import BaseModel, Field

class ExtractionResult(BaseModel):

date: str = Field(description="ISO 8601 date string")

channel: str = Field(description="Communication channel")

reference_id: str = Field(description="Identified reference code")

```

To review

[ ] Implement automated regression suites against golden prompt evaluation sets.

[ ] Measure token latency and cost trade-offs between few-shot and zero-shot setups.

[x] Configure delimiter-based prompt framing to defend against prompt injection.

References

OpenAI Prompt Engineering Guide

Anthropic Interactive Prompt Engineering Tutorial

DSPy Framework Documentation

Jarvis Interviews
Jarvis