prompt-engineering-best-practices
Skill2 starsChanged 3 months agoMITView on GitHub
Best practices for designing high-quality prompts: Chain-of-Thought, Few-shot, Role Prompting, Self-Consistency, and output structuring. Apply to system, task, and template prompts.
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 163
Use delimiters, schemas, and formats to guarantee consistent output.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Prompt Engineering Best Practices
Invoke when creating, reviewing, or improving prompts for LLMs. Ensures consistency, accuracy, and reliability across all prompt types.
The Six Pillars
| Pillar | Purpose | When to Use |
| Role Prompting | Establish expertise, tone, constraints | Every prompt |
| Context & Constraints | Narrow scope, prevent hallucination | Every prompt |
| Chain-of-Thought (CoT) | Improve reasoning on complex tasks | Math, logic, multi-step decisions |
| Few-Shot Prompting | Teach output format by example | Structured outputs, creative writing, code |
| Self-Consistency | Reduce randomness, increase reliability | Critical decisions, code generation |
| Output Structuring | Guarantee parseable, consistent format | APIs, tables, JSON, checklists |
1. Role Prompting
Define who the model is and what expertise it brings.
Template
You are a [role] with [X] years of experience in [domain].
Your specialty is [specific area].
You communicate in [tone] and prioritize [values].Good
You are a senior QA automation engineer with 8 years of experience in web and mobile testing.
Your specialty is designing maintainable test frameworks with Playwright and Appium.
You communicate directly and prioritize test reliability over coverage quantity.Bad
You are a QA engineer.Anti-Patterns
| Bad | Good |
| "Be helpful" | "You are a security auditor who flags every hardcoded secret" |
| "Write good code" | "You write production Python following PEP 8 and type hints" |
| "Answer questions" | "You answer as a staff engineer who explains trade-offs" |
2. Context & Constraints
Provide the model with boundaries before the task.
## Context
- Tech stack: Python 3.11, FastAPI, PostgreSQL, pytest
- Team size: 5 developers, 1 QA
- CI/CD: GitHub Actions with 10-minute timeout
## Constraints
- Max 50 lines per function
- Use `async`/`await` for I/O
- No external dependencies beyond `requirements.txt`3. Chain-of-Thought (CoT)
For reasoning tasks, instruct the model to think step by step before answering.
Zero-Shot CoT
Before answering, think step by step:
1. Identify the problem type
2. Break it into sub-problems
3. Solve each sub-problem
4. Verify the solution against constraints
5. Provide the final answerFew-Shot CoT
Q: A store has 15 apples. They sell 7, then receive 12 more. How many apples?
Let's think step by step.
Step 1: Start with 15 apples.
Step 2: Subtract 7 sold: 15 - 7 = 8.
Step 3: Add 12 received: 8 + 12 = 20.
Answer: 20 apples.
Q: A test suite has 120 tests. 30% are flaky. After fixing 60% of flaky tests, how many flaky remain?
Let's think step by step.4. Few-Shot Prompting
Provide input/output pairs to teach the model the desired format.
Template
## Example 1
Input: [user input]
Output:[desired output]
## Example 2
Input: [user input]
Output:[desired output]
## Task
Input: [actual user input]
Output:Few-Shot with Reasoning
## Example 1 — Test Case Generation
Requirement: "Users can log in with email and password."
Reasoning: This is a happy-path authentication test. Need valid credentials, login action, and dashboard assertion.
Output:
| ID | Scenario | Steps | Expected |
|----|----------|-------|----------|
| TC-01 | Valid login | 1. Enter email 2. Enter password 3. Click Login | Dashboard loads |
## Example 2 — Edge Case
Requirement: "Users can log in with email and password."
Reasoning: This tests the boundary of empty password field, which should trigger validation before API call.
Output:
| ID | Scenario | Steps | Expected |
|----|----------|-------|----------|
| TC-02 | Empty password | 1. Enter email 2. Leave password blank 3. Click Login | Inline validation error "Password is required" |5. Self-Consistency
Generate multiple reasoning paths and select the most consistent answer.
Generate 3 independent answers to this question.
For each answer, show your reasoning.
Then vote: which answer appears most frequently and is best supported?
Provide the consensus answer as the final output.6. Output Structuring
Use delimiters, schemas, and formats to guarantee consistent output.
## Output Format
Respond ONLY in the following markdown structure:
### Analysis
[Brief analysis in 1-2 sentences]
### Recommendation
[Clear recommendation]
### Rationale
[3 bullet points max]
### Confidence
[High / Medium / Low] with brief justificationJSON Mode
Respond with valid JSON only, no markdown, no explanations:
{
"test_cases": [
{
"id": "string",
"scenario": "string",
"steps": ["string"],
"expected": "string",
"priority": "High|Medium|Low"
}
],
"risks": ["string"],
"automation_candidates": ["string"]
}Prompt Quality Checklist
- Role is specific (not generic "assistant")
- Context and constraints are explicit
- Task is broken into clear steps (CoT for complex tasks)
- Few-shot examples cover happy path + edge cases
- Output format is defined with delimiters
- Anti-patterns or "what NOT to do" are stated
- Length is under 1000 lines (prefer 300-500)
- No ambiguous terms ("good", "best", "appropriate")
Common Anti-Patterns
| Anti-Pattern | Why It Fails | Fix |
| "Write a good test" | Subjective, no criteria | "Write a pytest test with Arrange-Act-Assert, max 20 lines, using fixtures for DB setup" |
| No output format | Inconsistent structure | Define markdown table or JSON schema |
| No examples | Model guesses format | Provide 2-3 input/output pairs |
| Vague role | Generic tone, no expertise | "You are a senior SRE with Kubernetes in production" |
| No constraints | Hallucination, scope creep | "Use only standard library. No third-party packages." |
In this repository45 other files it gives its agents.
- AGENTS.mdAGENTS.md
- allure-reportsSkill
- android-nativeSkill
- appian-lowcodeSkill
- appium-mobileSkill
- behave-bddSkill
- BiDiWave Cross-BrowserSkill
- BiDiWave Network InterceptionSkill
- CDPWave DebuggingSkill
- CDPWave TestingSkill
- db2-oracleSkill
- ebook-writerSkill
- flask-apiSkill
- flet-desktopSkill
- google-crawling-indexingSkill
- google-ranking-appearanceSkill
- google-seo-fundamentalsSkill
- google-seo-monitoringSkill
- jinja2-templatesSkill
- jmeter-load-testingSkill
- k6-load-testingSkill
- karate-api-testingSkill
- octane-almSkill
- paramiko-sshSkill
- postman-api-automationSkill
- prestashop-moduleSkill
- pytest-advancedSkill
- robot-frameworkSkill
- salesforce-devSkill
- sonarqube-quality-gatesSkill
- sql-serverSkill
- Skill NameSkill
- testcontainersSkill
- wave-ecosystem-guideSkill
- WaveXis AccessibilitySkill
- WaveXis CI/CD IntegrationSkill
- wavexis-cli-automationSkill
- wavexis-mcp-agent-integrationSkill
- WaveXis Network TestingSkill
- WaveXis Performance AuditSkill
- WaveXis Session RecordingSkill
- WaveXis Web ScrapingSkill
- webdriverioSkill
- wordpress-themesSkill
- xctest-iosSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

