Foundation

Core Principles of Prompt Engineering

Good prompting is not about magic wording. It is about reducing ambiguity, giving the model the right working context, and shaping the output so it is useful inside a real engineering workflow.

1. Define the model’s job clearly

Tell the model what role it should play and what kind of output you expect. A weak prompt says “explain this code.” A strong prompt says “act as a senior Java reviewer and explain the code’s behavior, risks, and possible refactoring opportunities.”

2. Give useful context, not random detail

The model performs better when it has the right constraints and background. Include framework, language version, business rules, target audience, and expected output format.

3. Ask for structured output

Structured output is easier to verify and reuse. Prefer headings, tables, JSON, checklists, or side-by-side comparisons instead of a loose paragraph.

4. Separate thinking stages

For bigger tasks, split prompts into phases such as analyse → plan → implement → validate. This often produces more reliable results than asking for everything in one shot.

5. Add a quality bar

Ask the model to check assumptions, mention uncertainty, or list trade-offs. This reduces shallow “looks correct” answers.

Good prompt anatomy

PartPurposeExample
RoleSets the perspectiveAct as a senior Spring Boot architect.
ContextProvides the situationThis service handles payment reconciliation in batch mode.
TaskStates what to doFind design issues and propose a safer structure.
ConstraintsPrevents driftKeep the solution compatible with Java 21 and PostgreSQL.
Output shapeMakes the answer reusableReturn: summary, risks, improved code, and migration steps.