prompt-engineering-patterns

Implements few-shot, chain-of-thought, and structured-output prompt patterns for LLM applications.

3|1|Updated Nov 30, 2025
One-click install
npx skills add https://github.com/PALabs-v1/AI_friend --skill prompt-engineering-patterns-palabs-v1
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: prompt-engineering-patterns
Source: https://github.com/PALabs-v1/AI_friend/tree/main/.agents/skills/prompt-engineering-patterns
Command: npx skills add https://github.com/PALabs-v1/AI_friend --skill prompt-engineering-patterns-palabs-v1

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 an optimization script to systematically improve accuracy, consistency, and token efficiency. ## Core Features & Use Cases - Reasoning Patterns: Implement zero-shot and few-shot chain-of-thought, self-consistency voting, tree-of-thought, and verification steps for complex reasoning tasks. - Structured Outputs & Templates: Enforce Pydantic schemas, JSON mode, and modular prompt templates with variable interpolation and conditional sections. - Prompt Optimization: Run A/B tests and iterative refinement with the included optimize-prompt.py script, tracking accuracy, latency, and token metrics. - Use Case: When building a sentiment analysis feature that returns malformed JSON, apply the structured output pattern with Pydantic validation and error-recovery fallback to get reliable, parseable responses. ## Quick Start Ask the AI to rewrite your existing prompt using the structured output pattern with Pydantic validation and a chain-of-thought verification step.

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 instruct the model to respond with JSON matching that schema. Parse the response with json.loads and validate it against the model, with a fallback prompt if parsing fails.

How to use chain-of-thought prompting for reasoning tasks?

Append a trigger like "Let's think step by step" for zero-shot CoT, or provide examples with explicit reasoning traces for few-shot CoT. For higher accuracy, sample multiple reasoning paths and take a majority vote using self-consistency.

How do I select few-shot examples for a prompt?

Use semantic similarity selection with embeddings to retrieve the examples most similar to each query, or diversity sampling via clustering to cover edge cases. Balance example count against your context window token budget.

Does prompt caching reduce latency and cost?

Yes, marking long repeated system prompts with cache_control in the Anthropic API avoids reprocessing them on each request. This reduces both latency and token costs for applications reusing the same prompt prefix.

When should I not use chain-of-thought prompting?

Skip CoT for simple factual lookups, direct retrieval, creative writing, and latency-sensitive real-time applications. The extra reasoning tokens add cost and delay without improving accuracy on trivial tasks.