prompt-engineering-patterns

Implements prompt engineering patterns for LLM applications using LangChain and Pydantic.

Updated Apr 13, 2026
One-click install
npx skills add https://github.com/scoots31/engineering-playbook --skill prompt-engineering-patterns-scoots31
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: prompt-engineering-patterns
Source: https://github.com/scoots31/engineering-playbook/tree/main/references/prompt-engineering-patterns
Command: npx skills add https://github.com/scoots31/engineering-playbook --skill prompt-engineering-patterns-scoots31

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? LLM prompts often produce inconsistent, unparseable, or low-quality outputs in production. This Skill provides proven patterns for structured outputs, chain-of-thought reasoning, few-shot learning, and error recovery so prompts behave predictably. ## Core Features & Use Cases - Structured Outputs: Enforce JSON schemas with Pydantic models and LangChain's with_structured_output for reliably parseable responses. - Reasoning Patterns: Apply chain-of-thought, self-consistency, and verification steps to improve answer accuracy on complex tasks. - Few-Shot & Templates: Dynamically select examples with semantic similarity and build reusable, parameterized prompt templates. - Use Case: When building a customer support assistant, use dynamic few-shot selection to retrieve the most similar past interactions and generate consistent, on-brand responses. ## Quick Start Ask the AI to convert a plain-language request into a structured output prompt with a Pydantic schema and error fallback.

Frequently Asked Questions about prompt-engineering-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I get structured JSON output from an LLM?

Define a Pydantic model describing the expected fields, then use LangChain's with_structured_output method or instruct the model to respond with JSON matching the schema. Parse the response and validate it against the model to catch malformed outputs.

How to implement few-shot prompting with dynamic example selection?

Use SemanticSimilarityExampleSelector from LangChain with an embedding model like VoyageAI and a vector store such as Chroma. It retrieves the k most similar examples to each query and injects them into the prompt automatically.

What is chain-of-thought prompting and when should I use it?

Chain-of-thought prompting asks the model to reason step by step before answering, improving accuracy on multi-step problems. Use it for math, logic, or analysis tasks; simple factual queries usually do not benefit from the extra tokens.

Does prompt caching reduce LLM API costs?

Yes, Anthropic's prompt caching lets you mark long system prompts with cache_control so repeated requests reuse the cached prefix. This reduces both latency and token costs when the same system prompt is sent across many calls.

Why does my LLM return malformed JSON sometimes?

Models can produce invalid JSON due to ambiguous instructions, missing schema details, or token limits truncating output. Handle this with try/except around json.loads and Pydantic validation, plus a fallback prompt that extracts a simpler answer.