prompt-engineering-patterns

Design, test, and optimize LLM prompts using few-shot, chain-of-thought, and structured output patterns.

1|Updated May 10, 2026
One-click install
npx skills add https://github.com/Tgoldi/claude-skills --skill prompt-engineering-patterns-tgoldi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: prompt-engineering-patterns
Source: https://github.com/Tgoldi/claude-skills/tree/main/prompt-engineering-patterns
Command: npx skills add https://github.com/Tgoldi/claude-skills --skill prompt-engineering-patterns-tgoldi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires numpy, and includes scripts (resource) and references (resource) and assets (resource) components.

What problem does it solve? LLM prompts often produce inconsistent, unparseable, or low-quality outputs in production. This Skill provides proven prompt engineering patterns and tooling to make LLM outputs reliable, structured, and measurable. ## Core Features & Use Cases - Prompt Pattern Library: Implement few-shot learning, chain-of-thought reasoning, tree-of-thought, self-consistency, and structured JSON outputs with Pydantic schema enforcement. - Prompt Optimization: Run A/B tests, measure accuracy/latency/token metrics, and iteratively refine prompts using the included optimization script. - Template Systems: Build reusable, composable prompt templates with variable interpolation, conditional sections, and role-based system prompts. - Use Case: You are building a sentiment analysis feature and getting inconsistent outputs. Use this Skill to apply structured output with a Pydantic schema, add dynamically selected few-shot examples, and A/B test prompt variations until accuracy exceeds your target. ## Quick Start Ask the AI to rewrite your prompt using chain-of-thought reasoning and structured JSON output with a Pydantic schema, then evaluate it against your test cases.

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 Claude in Python?

Use Pydantic models with LangChain's with_structured_output method or instruct the model to respond with JSON matching an explicit schema, then parse with json.loads. Wrap parsing in try/except to handle malformed outputs with a fallback prompt.

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

Embed your examples and queries with a model like VoyageAI, then use SemanticSimilarityExampleSelector with a vector store like Chroma to retrieve the k most similar examples per query. Insert selected examples into the prompt before the user input.

When should I use chain-of-thought prompting?

Use chain-of-thought for math, logical reasoning, multi-step planning, and code debugging tasks. Skip it for simple factual lookups, creative writing, or latency-sensitive applications where step-by-step reasoning adds unnecessary tokens.

How do I A/B test two prompt variations?

Run both prompts against the same test suite, measuring accuracy, latency, and token usage per variant. Use a statistical significance test like a t-test on the results to confirm the winner rather than relying on small sample differences.

Why does my prompt produce inconsistent outputs?

Inconsistency usually comes from vague instructions, missing output format constraints, or untested edge cases. Add explicit format requirements, representative few-shot examples, and a verification step, then measure consistency across repeated runs.

How can I reduce prompt token usage without losing quality?

Remove filler phrases, consolidate multi-sentence instructions into numbered steps, and use prompt caching for repeated system prompts via cache_control. Measure accuracy before and after to confirm quality is preserved.