Prompting for Software Development
Learn to give AI coding assistants the context, constraints, and acceptance criteria they need, and to maintain a project instruction file and prompt library.
Introduction
“Add CSV import” is a task. It is not a specification. An assistant given that sentence will make dozens of silent decisions: file size limits, encoding, what counts as invalid, how errors are reported, which libraries to use. Some will be wrong for your system, and you will discover them one at a time.
Good prompting for software is mostly good engineering communication: clear goals, relevant context, explicit constraints, and testable acceptance criteria. This lesson turns that into practical patterns.
Learning Objectives
- Structure a development prompt with goal, context, constraints, interfaces, and acceptance criteria.
- Apply prompt patterns such as plan-first, test-first, and ask-questions-first.
- Manage context: what to include, what to leave out, and how to reference project documents.
- Create a project instruction file that carries conventions across sessions.
- Debug with AI using effective problem descriptions.
- Build a small, maintained prompt library.
1. Anatomy of a Good Development Prompt
| Element | Purpose | Example |
|---|---|---|
| Goal | What outcome, in one or two sentences | Validate rows of an uploaded feedback CSV |
| Context | Where this fits; relevant code and decisions | Module imports, ADR-004 (modular monolith) |
| Constraints | Stack, style, limits, what not to do | Python 3.12, no new dependencies, no I/O in the validator |
| Interface | Signatures, inputs, outputs, errors | validate_row(row: dict) -> ValidationResult |
| Acceptance criteria | Observable conditions for done | A row without body is rejected with code MISSING_BODY |
| Examples | Representative inputs and outputs | Valid row, row with empty body, row with 10,000-character body |
| Output format | How you want the answer | Show a plan first; then a diff; then tests |
You will not need every element every time. The smaller and clearer the task, the shorter the prompt can be. The larger or riskier the task, the more of this belongs in the prompt, or better, in a written specification you reference.
2. Reference Your Artifacts
The requirements and architecture work from earlier courses is your best prompt material. Reference it rather than retyping it:
- SRS requirement IDs and acceptance criteria: “Implement FR-IMP-02 as written below.”
- ADRs: “Follow ADR-004: no direct calls between modules except through their public interface.”
- Data model and API contract: paste the relevant excerpt, not the whole document.
- Definition of Done from the sprint plan.
Paste what the assistant needs for this task. Irrelevant context is not free: it dilutes attention and can mislead.
3. Prompt Patterns That Work
Plan first. Ask for an approach before code, and review it.
1
2
3
4
Before writing code, propose a plan for implementing the task below:
the files you would change or add, the main functions, and the
edge cases you will handle. List any assumptions and questions.
Wait for my approval before implementing.
Test first. Ask for tests that express the acceptance criteria, review them, then ask for the implementation.
Ask questions first. Useful for ambiguous work.
1
2
Before implementing, ask me up to five clarifying questions whose
answers would most change the design. Do not proceed until I answer.
Constrain explicitly. State what to avoid: “no new dependencies,” “do not modify files outside imports/,” “do not change public function signatures.”
Show examples. Input and output examples remove ambiguity faster than prose.
Request alternatives. “Give two approaches with trade-offs and recommend one, noting what would change your recommendation.”
Small steps. One function, one endpoint, one migration at a time. If a step feels large, ask the assistant to break it down and do the first piece.
Critique mode. After generating, ask: “List the weaknesses, edge cases, and failure modes of this implementation.”
4. Context Management
Assistants work within a limited context. Practical habits:
- Start fresh sessions for unrelated tasks; old context can mislead.
- Restate key constraints in long sessions rather than assuming they persisted.
- Point to existing code as the pattern to follow: “Follow the structure of
imports/csv_parser.py.” - Provide failing output verbatim (error messages, stack traces), not paraphrases.
- Prefer references over copies when your tool can retrieve files, and verify what it actually read.
- Exclude secrets and personal data from everything you paste.
If an answer ignores something you provided, do not assume malice or memory: check whether it was in context at all.
5. The Project Instruction File
Most assistants can read a project-level instruction file (named differently by different tools). It carries stable guidance so you do not repeat it every session. Keep it short, accurate, and in version control.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Assistant instructions: SignalDesk
## Architecture
- Modular monolith; modules: workspaces, imports, evidence, summaries.
- Modules communicate only through their public `api.py`. No imports
of another module's internals. (ADR-004)
## Conventions
- Python 3.12, type hints required, formatted with the project formatter.
- Database access only through repository classes.
- Every query on tenant data must filter by workspace_id.
## Commands
- Run tests: `make test` Lint and types: `make check`
## Rules
- No new dependencies without asking.
- Never log personal data or raw feedback text.
- Do not modify migrations that have been merged.
- When uncertain, ask rather than guess.
Treat it as living documentation: when the assistant repeatedly makes the same mistake, add a line. When a line is outdated, remove it. Review changes to this file like code.
6. Debugging With AI
A good debugging prompt gives the assistant what a colleague would need:
1
2
3
4
5
6
7
8
9
10
11
Problem: [one sentence]
Expected: [what should happen]
Actual: [what happens, with exact error or output]
Steps to reproduce: [minimal]
Relevant code: [excerpt]
Environment: [versions]
What I already tried: [list]
Propose up to three hypotheses ranked by likelihood, and for each,
a quick experiment to confirm or rule it out. Do not change code
until we have identified the cause.
The key discipline: diagnose before patching. An assistant asked to “fix it” will often change something plausible. Insist on a hypothesis and a test, then fix.
7. Common Prompting Mistakes
- Vague goals: “Make the import better.”
- Giant tasks: “Build the whole import module.”
- Missing constraints: results that violate architecture or add dependencies.
- No acceptance criteria: no way to tell whether the output is right.
- Accepting the first answer: not asking for alternatives or critique.
- Prompt thrashing: repeatedly tweaking wording instead of clarifying the task or splitting it.
- Pasting everything: burying the relevant facts.
8. A Small Prompt Library
Keep reusable prompts in the repository (for example, docs/prompts/): plan a change, write tests from criteria, explain this code, review this diff, draft a commit message, debug with hypotheses. For each, note the purpose, required inputs, and an example of good output. Review and prune it occasionally; a prompt that no longer helps is clutter.
9. Practical Exercise
For SignalDesk (or your project):
- Write the assistant instruction file with architecture, conventions, commands, and rules.
- Take one requirement from your first sprint and write a full prompt with every element from section 1.
- Run it twice: once with only a one-line task, and once with your full prompt. Compare the results for correctness, convention adherence, and number of corrections needed.
- Use the plan-first pattern on a different task, and record at least one thing you changed in the plan before implementation.
- Create the prompt library with at least four prompts.
Verification
You are ready to continue when:
- The instruction file is committed and accurately describes the project.
- At least one prompt references requirement IDs, ADRs, and acceptance criteria.
- You have compared a vague prompt with a structured one and recorded the difference.
- The prompt library exists with purposes and inputs.
Key Takeaways
- Good prompts are good specifications: goal, context, constraints, interface, acceptance criteria, examples.
- Reference your requirements and ADRs instead of retyping them.
- Plan first, test first, ask questions first, and keep steps small.
- Put stable guidance in an instruction file, and diagnose before patching.
What’s Next?
Before the assistant writes code at scale, we need a safety net. Next, we set up Git workflows that keep AI-assisted changes small, reviewable, and reversible.