← Back

Prompt Patterns

AI Patterns Python Any LLM
📝

Problem

AI prompts that work in testing break in production. Small changes in wording cause wildly different outputs. There's no systematic approach—just trial and error.

Solution

A library of proven patterns that consistently produce better results.

  • Chain of Thought: "Think step by step..."
  • Few-Shot: Show examples to guide format
  • Role-Based: "You are an expert..."
  • Structured Output: Force consistent JSON
  • Self-Consistency: Multiple answers, majority vote

Demo

Take a simple task like "summarize this text." Compare a naive prompt vs a structured prompt with chain-of-thought. See the dramatic improvement in quality and consistency.

Basic prompt
Pattern applied

Run it

git clone https://github.com/freshveejay/prompt-engineering-patterns
cd prompt-engineering-patterns
pip install -r requirements.txt
python prompts.py