What is prompt engineering?
Prompt engineering is the art of phrasing queries to language models so that you get predictable, accurate and useful results.
A good prompt = clear context + a specific task + a response format.
Bad vs good prompts
❌ Bad — too general:
Write some PHP code.
✅ Good — specific:
Write a PHP 8.3 function that:
- takes an array of strings
- filters out elements longer than 5 characters
- returns a new array with the results
- uses array_filter and fn()
Add a usage example with var_dump().
Techniques
1. System prompt — assign a role
You are a senior PHP developer with 10 years of experience in Symfony.
Answer concisely. Write code following PSR-12.
If a question is unclear, ask before answering.
2. Few-shot — show examples
Convert titles into slugs:
"Hello World" → "hello-world"
"How are you?" → "how-are-you"
"PHP 8.3 Tutorial" → "php-8-3-tutorial"
"Zażółć gęślą jaźń" → ?
3. Chain of thought — think step by step
Solve this performance problem step by step:
1. Describe what this code does
2. Identify the bottleneck
3. Propose an optimization
4. Show the fixed code
Code:
[paste code]
4. Output format — specify the response format
Respond in JSON format:
{
"problem": "...",
"solution": "...",
"code": "..."
}
Tools
| Tool | Use |
|---|---|
| Anthropic Console | Testing prompts, comparing models |
| Claude Code | Coding assistant in the terminal |
| GitHub Copilot | Code completion in the IDE |
| LangChain | Building applications with LLMs |
A prompt for code review
Analyze the PHP code below as a senior developer.
Look for:
- security bugs (SQL injection, XSS, CSRF)
- performance problems
- SOLID violations
- missing error handling
Format:
## Critical
- [problem description] → [suggested fix]
## Important
- ...
## Suggestions
- ...
Code:
```php
[your code]
---
## LLM limitations
- **hallucinations** — the model may make up facts; always verify
- **knowledge cutoff** — the model doesn't know the latest libraries
- **context** — long conversations may "lose" earlier decisions
- **determinism** — the same prompt may give different answers (the `temperature` parameter)