Crafting Production-Grade Prompts
To get consistent, high-quality results from Large Language Models (LLMs), prompts must provide Role, Context, Task, Constraints, and Output Format.
The 5-Part Prompt Framework
- Persona / Role: Define who the AI is acting as.
- Context: Give relevant background information.
- Instruction / Task: Clearly define the specific task to perform.
- Constraints: State what NOT to do and limits (e.g. no markdown, max 100 words).
- Output Specification: Define the exact structure (JSON, Markdown table, YAML).
Example: Weak Prompt vs Engineered Prompt
Weak Prompt
Write a login function for PHP.
Production Prompt Template
You are a senior cybersecurity and backend PHP 8.4 architect.
Task: Write a secure user authentication function that verifies a user's password using password_verify() and issues a secure session.
Constraints:
- Use PHP 8.4 strict typing (declare(strict_types=1);).
- Implement rate limiting prevention against brute force attacks.
- Do not expose detailed error messages to the client.
- Return response as JSON containing: { "success": bool, "message": string }.