prompt-engineering
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePrompt Engineering
Prompt Engineering(提示词工程)
This skill provides comprehensive frameworks for creating, optimizing, and implementing advanced prompt patterns that significantly improve LLM performance across various tasks and models.
此技能提供了全面的框架,用于创建、优化和实施高级提示词模式,可显著提升LLM在各类任务和模型中的性能。
When to Use This Skill
何时使用此技能
Use this skill when:
- Creating new prompts for complex reasoning or analytical tasks
- Optimizing existing prompts for better accuracy or efficiency
- Implementing few-shot learning with strategic example selection
- Designing chain-of-thought reasoning for multi-step problems
- Building reusable prompt templates and systems
- Developing system prompts for consistent model behavior
- Troubleshooting poor prompt performance or failure modes
- Scaling prompt systems for production use cases
在以下场景中使用此技能:
- 创建用于复杂推理或分析任务的新提示词
- 优化现有提示词以提升准确性或效率
- 实施带有策略性示例选择的few-shot learning
- 为多步骤问题设计chain-of-thought reasoning
- 构建可复用的提示词模板和系统
- 开发用于确保模型行为一致性的系统提示词
- 排查提示词性能不佳或失效的问题
- 针对生产用例扩展提示词系统
Core Prompt Engineering Patterns
核心提示词工程模式
1. Few-Shot Learning Implementation
1. Few-shot Learning 实施策略
Select examples using semantic similarity and diversity sampling to maximize learning within context window constraints.
通过语义相似度和多样性采样选择示例,以在上下文窗口限制内最大化学习效果。
Example Selection Strategy
示例选择策略
- Use for comprehensive selection frameworks
references/few-shot-patterns.md - Balance example count (3-5 optimal) with context window limitations
- Include edge cases and boundary conditions in example sets
- Prioritize diverse examples that cover problem space variations
- Order examples from simple to complex for progressive learning
- 使用获取全面的选择框架
references/few-shot-patterns.md - 在示例数量(3-5个为最优)和上下文窗口限制之间取得平衡
- 在示例集中包含边缘情况和边界条件
- 优先选择覆盖问题空间变体的多样化示例
- 按从简单到复杂的顺序排列示例,实现渐进式学习
Few-Shot Template Structure
Few-shot 模板结构
Example 1 (Basic case):
Input: {representative_input}
Output: {expected_output}
Example 2 (Edge case):
Input: {challenging_input}
Output: {robust_output}
Example 3 (Error case):
Input: {problematic_input}
Output: {corrected_output}
Now handle: {target_input}Example 1 (Basic case):
Input: {representative_input}
Output: {expected_output}
Example 2 (Edge case):
Input: {challenging_input}
Output: {robust_output}
Example 3 (Error case):
Input: {problematic_input}
Output: {corrected_output}
Now handle: {target_input}2. Chain-of-Thought Reasoning
2. Chain-of-Thought 推理
Elicit step-by-step reasoning for complex problem-solving through structured thinking patterns.
通过结构化思维模式引导复杂问题的逐步推理。
Implementation Patterns
实施模式
- Reference for detailed reasoning frameworks
references/cot-patterns.md - Use "Let's think step by step" for zero-shot CoT initiation
- Provide complete reasoning traces for few-shot CoT demonstrations
- Implement self-consistency by sampling multiple reasoning paths
- Include verification and validation steps in reasoning chains
- 参考获取详细的推理框架
references/cot-patterns.md - 使用"Let's think step by step"启动零样本CoT推理
- 为小样本CoT演示提供完整的推理轨迹
- 通过采样多条推理路径实现自一致性
- 在推理链中包含验证和确认步骤
CoT Template Structure
CoT 模板结构
Let's approach this step-by-step:
Step 1: {break_down_the_problem}
Analysis: {detailed_reasoning}
Step 2: {identify_key_components}
Analysis: {component_analysis}
Step 3: {synthesize_solution}
Analysis: {solution_justification}
Final Answer: {conclusion_with_confidence}Let's approach this step-by-step:
Step 1: {break_down_the_problem}
Analysis: {detailed_reasoning}
Step 2: {identify_key_components}
Analysis: {component_analysis}
Step 3: {synthesize_solution}
Analysis: {solution_justification}
Final Answer: {conclusion_with_confidence}3. Prompt Optimization Workflows
3. 提示词优化流程
Implement iterative refinement processes with measurable performance metrics and systematic A/B testing.
实施带有可量化性能指标和系统性A/B测试的迭代优化流程。
Optimization Process
优化流程
- Use for comprehensive optimization strategies
references/optimization-frameworks.md - Measure baseline performance before optimization attempts
- Implement single-variable changes for accurate attribution
- Track metrics: accuracy, consistency, latency, token efficiency
- Use statistical significance testing for A/B validation
- Document optimization iterations and their impacts
- 使用获取全面的优化策略
references/optimization-frameworks.md - 在尝试优化前先测量基准性能
- 实施单变量变更以确保准确归因
- 跟踪指标:准确性、一致性、延迟、Token效率
- 使用统计显著性测试进行A/B验证
- 记录优化迭代过程及其影响
Performance Metrics Framework
性能指标框架
- Accuracy: Task completion rate and output correctness
- Consistency: Response stability across multiple runs
- Efficiency: Token usage and response time optimization
- Robustness: Performance across edge cases and variations
- Safety: Adherence to guidelines and harm prevention
- 准确性:任务完成率和输出正确性
- 一致性:多次运行中的响应稳定性
- 效率:Token使用量和响应时间优化
- 鲁棒性:在边缘情况和变体场景下的性能表现
- 安全性:对准则和防伤害要求的遵守情况
4. Template Systems Architecture
4. 模板系统架构
Build modular, reusable prompt components with variable interpolation and conditional sections.
构建带有变量插值和条件片段的模块化、可复用提示词组件。
Template Design Principles
模板设计原则
- Reference for modular template frameworks
references/template-systems.md - Use clear variable naming conventions (e.g., ,
{user_input}){context} - Implement conditional sections for different scenario handling
- Design role-based templates for specific use cases
- Create hierarchical template composition patterns
- 参考获取模块化模板框架
references/template-systems.md - 使用清晰的变量命名规范(如、
{user_input}){context} - 为不同场景处理实现条件片段
- 为特定用例设计基于角色的模板
- 创建分层模板组合模式
Template Structure Example
模板结构示例
undefinedundefinedSystem Context
System Context
You are a {role} with {expertise_level} expertise in {domain}.
You are a {role} with {expertise_level} expertise in {domain}.
Task Context
Task Context
{if background_information}
Background: {background_information}
{endif}
{if background_information}
Background: {background_information}
{endif}
Instructions
Instructions
{task_instructions}
{task_instructions}
Examples
Examples
{example_count}
{example_count}
Output Format
Output Format
{output_specification}
{output_specification}
Input
Input
{user_query}
undefined{user_query}
undefined5. System Prompt Design
5. 系统提示词设计
Design comprehensive system prompts that establish consistent model behavior, output formats, and safety constraints.
设计全面的系统提示词,以确立一致的模型行为、输出格式和安全约束。
System Prompt Components
系统提示词组件
- Use for detailed design guidelines
references/system-prompt-design.md - Define clear role specification and expertise boundaries
- Establish output format requirements and structural constraints
- Include safety guidelines and content policy adherence
- Set context for background information and domain knowledge
- 参考获取详细设计指南
references/system-prompt-design.md - 定义清晰的角色规范和专业边界
- 确立输出格式要求和结构约束
- 包含安全准则和内容政策遵守要求
- 为背景信息和领域知识设置上下文
System Prompt Framework
系统提示词框架
You are an expert {role} specializing in {domain} with {experience_level} of experience.You are an expert {role} specializing in {domain} with {experience_level} of experience.Core Capabilities
Core Capabilities
- List specific capabilities and expertise areas
- Define scope of knowledge and limitations
- List specific capabilities and expertise areas
- Define scope of knowledge and limitations
Behavioral Guidelines
Behavioral Guidelines
- Specify interaction style and communication approach
- Define error handling and uncertainty protocols
- Establish quality standards and verification requirements
- Specify interaction style and communication approach
- Define error handling and uncertainty protocols
- Establish quality standards and verification requirements
Output Requirements
Output Requirements
- Specify format expectations and structural requirements
- Define content inclusion and exclusion criteria
- Establish consistency and validation requirements
- Specify format expectations and structural requirements
- Define content inclusion and exclusion criteria
- Establish consistency and validation requirements
Safety and Ethics
Safety and Ethics
- Include content policy adherence
- Specify bias mitigation requirements
- Define harm prevention protocols
undefined- Include content policy adherence
- Specify bias mitigation requirements
- Define harm prevention protocols
undefinedImplementation Workflows
实施流程
Workflow 1: Create New Prompt from Requirements
流程1:根据需求创建新提示词
-
Analyze Requirements
- Identify task complexity and reasoning requirements
- Determine target model capabilities and limitations
- Define success criteria and evaluation metrics
- Assess need for few-shot learning or CoT reasoning
-
Select Pattern Strategy
- Use few-shot learning for classification or transformation tasks
- Apply CoT for complex reasoning or multi-step problems
- Implement template systems for reusable prompt architecture
- Design system prompts for consistent behavior requirements
-
Draft Initial Prompt
- Structure prompt with clear sections and logical flow
- Include relevant examples or reasoning demonstrations
- Specify output format and quality requirements
- Incorporate safety guidelines and constraints
-
Validate and Test
- Test with diverse input scenarios including edge cases
- Measure performance against defined success criteria
- Iterate refinement based on testing results
- Document optimization decisions and their rationale
-
需求分析
- 识别任务复杂度和推理要求
- 确定目标模型的能力和局限性
- 定义成功标准和评估指标
- 评估是否需要few-shot learning或CoT推理
-
模式策略选择
- 对分类或转换任务使用few-shot learning
- 对复杂推理或多步骤问题应用CoT
- 为可复用提示词架构实施模板系统
- 为一致性行为要求设计系统提示词
-
起草初始提示词
- 以清晰的章节和逻辑流程构建提示词
- 包含相关示例或推理演示
- 明确输出格式和质量要求
- 融入安全准则和约束
-
验证与测试
- 使用多样化输入场景(包括边缘情况)进行测试
- 根据定义的成功标准衡量性能
- 根据测试结果进行迭代优化
- 记录优化决策及其依据
Workflow 2: Optimize Existing Prompt
流程2:优化现有提示词
-
Performance Analysis
- Measure current prompt performance metrics
- Identify failure modes and error patterns
- Analyze token efficiency and response latency
- Assess consistency across multiple runs
-
Optimization Strategy
- Apply systematic A/B testing with single-variable changes
- Use few-shot learning to improve task adherence
- Implement CoT reasoning for complex task components
- Refine template structure for better clarity
-
Implementation and Testing
- Deploy optimized prompts with controlled rollout
- Monitor performance metrics in production environment
- Compare against baseline using statistical significance
- Document improvements and lessons learned
-
性能分析
- 测量当前提示词的性能指标
- 识别失效模式和错误规律
- 分析Token效率和响应延迟
- 评估多次运行中的一致性
-
优化策略
- 实施带有单变量变更的系统性A/B测试
- 使用few-shot learning提升任务贴合度
- 为复杂任务组件实施CoT推理
- 优化模板结构以提升清晰度
-
实施与测试
- 通过受控发布部署优化后的提示词
- 在生产环境中监控性能指标
- 使用统计显著性与基准进行对比
- 记录改进成果和经验教训
Workflow 3: Scale Prompt Systems
流程3:扩展提示词系统
-
Modular Architecture Design
- Decompose complex prompts into reusable components
- Create template inheritance hierarchies
- Implement dynamic example selection systems
- Build automated quality assurance frameworks
-
Production Integration
- Implement prompt versioning and rollback capabilities
- Create performance monitoring and alerting systems
- Build automated testing frameworks for prompt validation
- Establish update and deployment workflows
-
模块化架构设计
- 将复杂提示词分解为可复用组件
- 创建模板继承层级
- 实施动态示例选择系统
- 构建自动化质量保证框架
-
生产环境集成
- 实现提示词版本控制和回滚能力
- 创建性能监控和告警系统
- 构建用于提示词验证的自动化测试框架
- 确立更新和部署流程
Quality Assurance
质量保证
Validation Requirements
验证要求
- Test prompts with at least 10 diverse scenarios
- Include edge cases, boundary conditions, and failure modes
- Verify output format compliance and structural consistency
- Validate safety guideline adherence and harm prevention
- Measure performance across multiple model runs
- 至少使用10种多样化场景测试提示词
- 包含边缘情况、边界条件和失效模式
- 验证输出格式合规性和结构一致性
- 确认对安全准则的遵守和防伤害措施的有效性
- 测量在多轮模型运行中的性能
Performance Standards
性能标准
- Achieve >90% task completion for well-defined use cases
- Maintain <5% variance across multiple runs for consistency
- Optimize token usage without sacrificing accuracy
- Ensure response latency meets application requirements
- Demonstrate robust handling of edge cases and unexpected inputs
- 对定义明确的用例实现>90%的任务完成率
- 在多次运行中保持<5%的方差以确保一致性
- 在不牺牲准确性的前提下优化Token使用
- 确保响应延迟满足应用要求
- 展示对边缘情况和意外输入的鲁棒处理能力
Integration with Other Skills
与其他技能的集成
This skill integrates seamlessly with:
- langchain4j-ai-services-patterns: Interface-based prompt design
- langchain4j-rag-implementation-patterns: Context-enhanced prompting
- langchain4j-testing-strategies: Prompt validation frameworks
- unit-test-parameterized: Systematic prompt testing approaches
此技能可与以下技能无缝集成:
- langchain4j-ai-services-patterns:基于接口的提示词设计
- langchain4j-rag-implementation-patterns:上下文增强型提示词
- langchain4j-testing-strategies:提示词验证框架
- unit-test-parameterized:系统性提示词测试方法
Resources and References
资源与参考
- : Comprehensive few-shot learning frameworks
references/few-shot-patterns.md - : Chain-of-thought reasoning patterns and examples
references/cot-patterns.md - : Systematic prompt optimization methodologies
references/optimization-frameworks.md - : Modular template design and implementation
references/template-systems.md - : System prompt architecture and best practices
references/system-prompt-design.md
- :全面的few-shot learning框架
references/few-shot-patterns.md - :Chain-of-thought推理模式和示例
references/cot-patterns.md - :系统性提示词优化方法
references/optimization-frameworks.md - :模块化模板设计与实施
references/template-systems.md - :系统提示词架构与最佳实践
references/system-prompt-design.md
Usage Examples
使用示例
Example 1: Classification Task with Few-Shot Learning
示例1:结合Few-shot Learning的分类任务
Classify customer feedback into categories using semantic similarity for example selection and diversity sampling for edge case coverage.Classify customer feedback into categories using semantic similarity for example selection and diversity sampling for edge case coverage.Example 2: Complex Reasoning with Chain-of-Thought
示例2:结合Chain-of-Thought的复杂推理
Implement step-by-step reasoning for financial analysis with verification steps and confidence scoring.Implement step-by-step reasoning for financial analysis with verification steps and confidence scoring.Example 3: Template System for Customer Service
示例3:客服场景的模板系统
Create modular templates with role-based components and conditional sections for different inquiry types.Create modular templates with role-based components and conditional sections for different inquiry types.Example 4: System Prompt for Code Generation
示例4:代码生成的系统提示词
Design comprehensive system prompt with behavioral guidelines, output requirements, and safety constraints.Design comprehensive system prompt with behavioral guidelines, output requirements, and safety constraints.Common Pitfalls and Solutions
常见陷阱与解决方案
- Overfitting examples: Use diverse example sets with semantic variety
- Context window overflow: Implement strategic example selection and compression
- Inconsistent outputs: Specify clear output formats and validation requirements
- Poor generalization: Include edge cases and boundary conditions in training examples
- Safety violations: Incorporate comprehensive content policies and harm prevention
- 示例过拟合:使用具有语义多样性的多样化示例集
- 上下文窗口溢出:实施策略性示例选择和压缩
- 输出不一致:明确指定输出格式和验证要求
- 泛化能力差:在训练示例中包含边缘情况和边界条件
- 安全违规:融入全面的内容政策和防伤害措施
Performance Optimization
性能优化
- Monitor token usage and implement compression strategies
- Use caching for repeated prompt components
- Optimize example selection for maximum learning efficiency
- Implement progressive disclosure for complex prompt systems
- Balance prompt complexity with response quality requirements
This skill provides the foundational patterns and methodologies for building production-ready prompt systems that consistently deliver high performance across diverse use cases and model types.
- 监控Token使用并实施压缩策略
- 对重复的提示词组件使用缓存
- 优化示例选择以最大化学习效率
- 为复杂提示词系统实施渐进式披露
- 在提示词复杂度与响应质量要求之间取得平衡
此技能为构建可投入生产环境的提示词系统提供了基础模式和方法,可在各类用例和模型类型中持续交付高性能表现。