Prompt Engineering
Skill Profile
(Select at least one profile to enable specific modules)
Overview
Comprehensive guide for LLM prompt engineering techniques and best practices. Prompt engineering is the art and science of crafting effective prompts to elicit desired outputs from language models.
Why This Matters
Prompt engineering is critical for:
- Performance: Well-crafted prompts reduce inference time and cost
- Accuracy: Clear instructions improve output quality
- Consistency: Standardized prompts ensure predictable behavior
- Cost Optimization: Efficient prompts reduce token usage
- Maintainability: Reusable templates are easier to maintain
- Model Flexibility: Good prompts work across different models
Core Concepts & Rules
1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
Inputs / Outputs / Contracts
Skill Composition
- Depends on: llm
- Compatible with: llm, rag
- Conflicts with: None
- Related Skills: llm, rag, agents
Quick Start / Implementation Example
- Review requirements and constraints
- Set up development environment
- Implement core functionality following patterns
- Write tests for critical paths
- Run tests and fix issues
- Document any deviations or decisions
# Example implementation following best practices
def example_function():
# Your implementation here
pass
Assumptions
- Basic understanding of Large Language Models (LLMs)
- Familiarity with AI/ML concepts
- Experience with using AI assistants or chatbots
- Understanding of natural language communication
- Knowledge of programming concepts (for code generation tasks)
Compatibility & Prerequisites
- Supported Versions:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Required AI Tools:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
- Dependencies:
- Language-specific package manager
- Build tools
- Testing libraries
- Environment Setup:
.env.example keys: API_KEY, DATABASE_URL (no values)
Test Scenario Matrix (QA Strategy)
| Type |
Focus Area |
Required Scenarios / Mocks |
| Unit |
Core Logic |
Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| Integration |
DB / API |
All external API calls or database connections must be mocked during unit tests |
| E2E |
User Journey |
Critical user flows to test |
| Performance |
Latency / Load |
Benchmark requirements |
| Security |
Vuln / Auth |
SAST/DAST or dependency audit |
| Frontend |
UX / A11y |
Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
Technical Guardrails & Security Threat Model
1. Security & Privacy (Threat Model)
- Top Threats: Injection attacks, authentication bypass, data exposure
2. Performance & Resources
3. Architecture & Scalability
4. Observability & Reliability
Agent Directives & Error Recovery
(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)
- Thinking Process: Analyze root cause before fixing. Do not brute-force.
- Fallback Strategy: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.
- Self-Review: Check against Guardrails & Anti-patterns before finalizing.
- Output Constraints: Output ONLY the modified code block. Do not explain unless asked.
Definition of Done (DoD) Checklist
Anti-patterns / Pitfalls
- ⛔ Don't: Log PII, catch-all exception, N+1 queries
- ⚠️ Watch out for: Common symptoms and quick fixes
- 💡 Instead: Use proper error handling, pagination, and logging
Reference Links & Examples
- Internal documentation and examples
- Official documentation and best practices
- Community resources and discussions
Versioning & Changelog
- Version: 1.0.0
- Changelog:
- 2026-02-22: Initial version with complete template structure
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: prompt-engineering-103description: Comprehensive guide for LLM prompt engineering techniques and best practices. Use when this capability is needed.4---56# Prompt Engineering78## Skill Profile9*(Select at least one profile to enable specific modules)*10- [ ] **DevOps**11- [x] **Backend**12- [ ] **Frontend**13- [ ] **AI-RAG**14- [ ] **Security Critical**1516## Overview17Comprehensive guide for LLM prompt engineering techniques and best practices. Prompt engineering is the art and science of crafting effective prompts to elicit desired outputs from language models.1819## Why This Matters20Prompt engineering is critical for:21- **Performance**: Well-crafted prompts reduce inference time and cost22- **Accuracy**: Clear instructions improve output quality23- **Consistency**: Standardized prompts ensure predictable behavior24- **Cost Optimization**: Efficient prompts reduce token usage25- **Maintainability**: Reusable templates are easier to maintain26- **Model Flexibility**: Good prompts work across different models2728---2930## Core Concepts & Rules3132### 1. Core Principles33- Follow established patterns and conventions34- Maintain consistency across codebase35- Document decisions and trade-offs3637### 2. Implementation Guidelines38- Start with the simplest viable solution39- Iterate based on feedback and requirements40- Test thoroughly before deployment414243## Inputs / Outputs / Contracts44#4546## Skill Composition47* **Depends on**: llm48* **Compatible with**: llm, rag49* **Conflicts with**: None50* **Related Skills**: llm, rag, agents5152## Quick Start / Implementation Example53541. Review requirements and constraints552. Set up development environment563. Implement core functionality following patterns574. Write tests for critical paths585. Run tests and fix issues596. Document any deviations or decisions6061```python62# Example implementation following best practices63def example_function():64 # Your implementation here65 pass66```676869## Assumptions70- Basic understanding of Large Language Models (LLMs)71- Familiarity with AI/ML concepts72- Experience with using AI assistants or chatbots73- Understanding of natural language communication74- Knowledge of programming concepts (for code generation tasks)7576## Compatibility & Prerequisites7778* **Supported Versions**:79 - Python 3.8+80 - Node.js 16+81 - Modern browsers (Chrome, Firefox, Safari, Edge)82* **Required AI Tools**:83 - Code editor (VS Code recommended)84 - Testing framework appropriate for language85 - Version control (Git)86* **Dependencies**:87 - Language-specific package manager88 - Build tools89 - Testing libraries90* **Environment Setup**:91 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)929394## Test Scenario Matrix (QA Strategy)9596| Type | Focus Area | Required Scenarios / Mocks |97| :--- | :--- | :--- |98| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |99| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |100| **E2E** | User Journey | Critical user flows to test |101| **Performance** | Latency / Load | Benchmark requirements |102| **Security** | Vuln / Auth | SAST/DAST or dependency audit |103| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |104105106## Technical Guardrails & Security Threat Model107108### 1. Security & Privacy (Threat Model)109* **Top Threats**: Injection attacks, authentication bypass, data exposure110- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII111- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager112- [ ] **Authorization**: Validate user permissions before state changes113114### 2. Performance & Resources115- [ ] **Execution Efficiency**: Consider time complexity for algorithms116- [ ] **Memory Management**: Use streams/pagination for large data117- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks118119### 3. Architecture & Scalability120- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection121- [ ] **Modularity**: Decouple logic from UI/Frameworks122123### 4. Observability & Reliability124- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`125- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`126- [ ] **Error Handling**: Standardized error codes, no bare except127- [ ] **Observability Artifacts**:128 - **Log Fields**: timestamp, level, message, request_id129 - **Metrics**: request_count, error_count, response_time130 - **Dashboards/Alerts**: High Error Rate > 5%131132133## Agent Directives & Error Recovery134*(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)*135136- **Thinking Process**: Analyze root cause before fixing. Do not brute-force.137- **Fallback Strategy**: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.138- **Self-Review**: Check against Guardrails & Anti-patterns before finalizing.139- **Output Constraints**: Output ONLY the modified code block. Do not explain unless asked.140141142## Definition of Done (DoD) Checklist143144- [ ] Tests passed + coverage met145- [ ] Lint/Typecheck passed146- [ ] Logging/Metrics/Trace implemented147- [ ] Security checks passed148- [ ] Documentation/Changelog updated149- [ ] Accessibility/Performance requirements met (if frontend)150151152## Anti-patterns / Pitfalls153154* ⛔ **Don't**: Log PII, catch-all exception, N+1 queries155* ⚠️ **Watch out for**: Common symptoms and quick fixes156* 💡 **Instead**: Use proper error handling, pagination, and logging157158159## Reference Links & Examples160161* Internal documentation and examples162* Official documentation and best practices163* Community resources and discussions164165166## Versioning & Changelog167168* **Version**: 1.0.0169* **Changelog**:170 - 2026-02-22: Initial version with complete template structure171172---173> Converted and distributed by [TomeVault](https://tomevault.io/claim/amnadtaowsoam) — claim your Tome and manage your conversions.174<!-- tomevault:4.0:skill_md:2026-04-13 -->