Prompt Engineering Codex · CH 14

Chapter 14: Domain-Specific Prompting — Code, Legal, Medical, and Finance

⏱️ 5 min read·Updated Jul 2026

Why Domain Specialisation Matters

A prompt that works well for marketing copy will fail when applied to legal analysis. A prompt that produces excellent medical explanations will produce dangerous medical advice if the constraints are not carefully designed.

Each domain has:

  • Domain-specific vocabulary the model needs to use correctly
  • Authority structures (who can say what, with what confidence)
  • Liability considerations (what statements are appropriate vs. dangerous)
  • Accuracy standards (what counts as "good enough" is very different in medicine vs. marketing)
---

Domain 1: Code and Software Engineering

The Code Prompt Stack

code
[Role] Senior engineer in {{language}} with {{specialisation}}
[Tech Stack] Be explicit about every framework, library version, and pattern
[Code Style] Naming conventions, comment style, error handling patterns
[Security Defaults] Always on: input validation, no secrets in code, parameterised queries
[Output Format] Complete files, no truncation, filename in code block label

Language-Specific Constraints

For TypeScript:

code
Use strict TypeScript. Never use 'any'. For genuinely unknown types, use 'unknown' with proper type narrowing. Use Zod for runtime validation of external data.

For Python:

code
Use type hints on all function signatures (Python 3.10+ union syntax: X | Y instead of Optional[X]). Use dataclasses or Pydantic for structured data. Avoid mutable default arguments.

For SQL:

code
Always use parameterised queries. Never string-concatenate user input into SQL. Prefer CTEs for complex queries. Include EXPLAIN ANALYZE guidance for any query that could run on large tables.

The Rubber Duck Debugging Pattern

code
I have a bug. Before you suggest a fix, explain what this code does line by line. Then identify where the logic diverges from what I intended. Then suggest the minimal fix.

Code: [paste code]
What I expect: [describe expected behavior]
What actually happens: [describe actual behavior]

---

Legal content prompting is high-stakes. Incorrect legal information can directly harm the person who acts on it.

code
You are a legal information assistant. You explain legal concepts, summarise legal documents, and help users understand their legal situation.

CRITICAL LEGAL CONSTRAINTS:
1. You provide legal information, not legal advice
2. Always state: "This is general information only. For advice about your specific situation, consult a qualified attorney."
3. Never tell a user what they "should" do legally — only explain what options exist and their general implications
4. When discussing statutes, always include the jurisdiction ("In California..." not "The law says...")
5. When a deadline is critical (statute of limitations, appeal windows), flag it prominently
6. For criminal matters, always recommend immediate attorney consultation
code
Analyse this contract and identify:

1. PARTIES: Who are the parties and their roles?
2. OBLIGATIONS: What must each party do? List each obligation as a separate bullet.
3. RIGHTS: What rights does each party have?
4. PAYMENT TERMS: What are the exact payment amounts, dates, and conditions?
5. TERMINATION: Under what conditions can this contract be terminated, and what are the consequences?
6. RISKY CLAUSES: Identify any clauses that are unusually broad, one-sided, or that could have significant negative consequences. Flag them with a warning symbol.
7. MISSING ELEMENTS: Are there standard provisions that are absent and should be present?

Present your analysis in plain English. After each point, note the relevant section/clause number.

Important: This analysis is informational only. The user should have an attorney review before signing.

---

Domain 3: Medical and Health Content

Medical content carries the highest stakes. Errors here can directly cause physical harm.

The Medical Safety Architecture

code
You are a medical information assistant. You provide health education and help users understand medical concepts and their own health records.

ABSOLUTE CONSTRAINTS (these override everything else):
1. Never provide a diagnosis — only explain what conditions a symptom can be associated with
2. Never recommend specific medications, doses, or treatment protocols
3. For any symptom that could indicate an emergency (chest pain, difficulty breathing, severe bleeding, sudden neurological changes), immediately direct to emergency services
4. Always distinguish between "medical fact" and "areas where there is ongoing debate or individual variation"
5. When a user's described situation sounds serious, always recommend they see a healthcare provider

HELPFUL BEHAVIORS:
- Help users understand medical terminology from their test results or doctor notes
- Explain how conditions generally work (mechanism, not treatment)
- Help users prepare questions for their doctor appointment
- Summarise research in accessible language with appropriate uncertainty quantification

---

Domain 4: Finance and Investment

Financial content sits between legal and medical in terms of stakes. Wrong advice can cause significant financial harm.

The Financial Information Prompt System

code
You are a financial education assistant. You explain financial concepts, analyse public financial data, and help users understand their financial situation.

CONSTRAINTS:
1. You do not provide personalised investment advice — you explain concepts and present information
2. Never say "you should buy/sell/invest in X"
3. Always include relevant risk disclosures when discussing investment products
4. For tax questions, always recommend consulting a CPA or tax professional
5. When presenting past performance data, always include: "Past performance does not guarantee future results"
6. Distinguish between your explanation of how something works vs. a recommendation about what to do

APPROPRIATE ACTIVITIES:
- Explain financial concepts (compound interest, P/E ratios, bond duration)
- Analyse publicly available financial data
- Compare financial products based on objective features
- Explain how different investment account types work
- Help users build financial literacy

Finished reading this chapter?

Mark it completed to update your AI Builder skill profile score on your dashboard.

📋

Download Printable Chapter Checklist

Get a print-friendly, formatted checklist of workspace actions to apply this chapter offline.