Chuyển đến nội dung
Skillpedia
Prompt và LLM41k · #6724

prompt-engineering-patterns

Skill này làm gì

Công cụ này giúp viết các chỉ dẫn tốt hơn cho trí tuệ nhân tạo. Nó dạy các kỹ thuật nâng cao để AI hiểu chính xác điều bạn muốn và đưa ra câu trả lời đáng tin cậy hơn.

Khi nào nên dùng

  • ✓Khi bạn muốn AI tạo ra câu trả lời chính xác hơn.
  • ✓Khi bạn xây dựng hệ thống AI cho các tác vụ phức tạp.
  • ✓Khi bạn muốn AI tuân theo một định dạng trả lời cụ thể.

Liên kết skill

https://github.com/wshobson/agents/blob/main/plugins/llm-application-dev/skills/prompt-engineering-patterns/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/wshobson/agents/blob/main/plugins/llm-application-dev/skills/prompt-engineering-patterns/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để cải thiện chỉ dẫn này cho AI: “Viết một bản tóm tắt về Chiến tranh thế giới thứ hai”?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ dạy AI suy nghĩ từng bước, học từ ví dụ và trình bày câu trả lời có cấu trúc. Điều này giúp AI hiểu hướng dẫn tốt hơn và tránh lỗi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Prompt Engineering Patterns

Master advanced prompt engineering techniques to maximize LLM performance, reliability, and controllability.

When to Use This Skill

  • Designing complex prompts for production LLM applications
  • Optimizing prompt performance and consistency
  • Implementing structured reasoning patterns (chain-of-thought, tree-of-thought)
  • Building few-shot learning systems with dynamic example selection
  • Creating reusable prompt templates with variable interpolation
  • Debugging and refining prompts that produce inconsistent outputs
  • Implementing system prompts for specialized AI assistants
  • Using structured outputs (JSON mode) for reliable parsing

Core Capabilities

1. Few-Shot Learning

  • Example selection strategies (semantic similarity, diversity sampling)
  • Balancing example count with context window constraints
  • Constructing effective demonstrations with input-output pairs
  • Dynamic example retrieval from knowledge bases
  • Handling edge cases through strategic example selection

2. Chain-of-Thought Prompting

  • Step-by-step reasoning elicitation
  • Zero-shot CoT with "Let's think step by step"
  • Few-shot CoT with reasoning traces
  • Self-consistency techniques (sampling multiple reasoning paths)
  • Verification and validation steps

3. Structured Outputs

  • JSON mode for reliable parsing
  • Pydantic schema enforcement
  • Type-safe response handling
  • Error handling for malformed outputs

4. Prompt Optimization

  • Iterative refinement workflows
  • A/B testing prompt variations
  • Measuring prompt performance metrics (accuracy, consistency, latency)
  • Reducing token usage while maintaining quality
  • Handling edge cases and failure modes

5. Template Systems

  • Variable interpolation and formatting
  • Conditional prompt sections
  • Multi-turn conversation templates
  • Role-based prompt composition
  • Modular prompt components

6. System Prompt Design

  • Setting model behavior and constraints
  • Defining output formats and structure
  • Establishing role and expertise
  • Safety guidelines and content policies
  • Context setting and background information

Quick Start

from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
from pydantic import BaseModel, Field

# Define structured output schema
class SQLQuery(BaseModel):
    query: str = Field(description="The SQL query")
    explanation: str = Field(description="Brief explanation of what the query does")
    tables_used: list[str] = Field(description="List of tables referenced")

# Initialize model with structured output
llm = ChatAnthropic(model="claude-sonnet-5")
structured_llm = llm.with_structured_output(SQLQuery)

# Create prompt template
prompt = ChatPromptTemplate.from_messages([
    ("system", """You are an expert SQL developer. Generate efficient, secure SQL queries.
    Always use parameterized queries to prevent SQL injection.
    Explain your reasoning briefly."""),
    ("user", "Convert this to SQL: {query}")
])

# Create chain
chain = prompt | structured_llm

# Use
result = await chain.ainvoke({
    "query": "Find all users who registered in the last 30 days"
})
print(result.query)
print(result.explanation)

Detailed patterns and worked examples

Detailed pattern documentation lives in references/details.md. Read that file when the navigation tier above is insufficient.

Best Practices

  1. Be Specific: Vague prompts produce inconsistent results
  2. Show, Don't Tell: Examples are more effective than descriptions
  3. Use Structured Outputs: Enforce schemas with Pydantic for reliability
  4. Test Extensively: Evaluate on diverse, representative inputs
  5. Iterate Rapidly: Small changes can have large impacts
  6. Monitor Performance: Track metrics in production
  7. Version Control: Treat prompts as code with proper versioning
  8. Document Intent: Explain why prompts are structured as they are

Common Pitfalls

  • Over-engineering: Starting with complex prompts before trying simple ones
  • Example pollution: Using examples that don't match the target task
  • Context overflow: Exceeding token limits with excessive examples
  • Ambiguous instructions: Leaving room for multiple interpretations
  • Ignoring edge cases: Not testing on unusual or boundary inputs
  • No error handling: Assuming outputs will always be well-formed
  • Hardcoded values: Not parameterizing prompts for reuse

Success Metrics

…

Câu hỏi thường gặp

“Chain-of-Thought” là gì?

Đó là kỹ thuật yêu cầu AI trình bày lý luận từng bước để đi đến đáp án, như thể đang suy nghĩ thành lời.

“Few-Shot Learning” là gì?

Đó là khi bạn đưa ra vài ví dụ về câu trả lời mong muốn trước khi đặt câu hỏi chính. AI học từ các ví dụ này.

Tại sao dùng “Structured Outputs”?

Điều này đảm bảo AI trả về thông tin theo định dạng có thể đoán trước, như JSON, giúp các chương trình khác dễ sử dụng thông tin đó.

Chi tiết

Mô tả gốc của tác giả

This skill should be used when the user asks to "optimize a prompt", "improve prompt performance", "design a prompt template", "write better prompts", "debug prompt issues", "use chain-of-thought", "structured prompting", "few-shot prompting", or wants to apply advanced prompt engineering patterns for production LLM applications.

repo: wshobson/agents

Độ phổ biến

Sao GitHub
41k
Vị trí xếp hạng
#6724
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự