Oct 26 2026

Prompt Engineering for Agents: Your System Prompt Is Now Production Code

Category: AI,AI Agent — disc7 @ 12:32 pm

Prompt Engineering for Agents: Your System Prompt Is Now Production Code

Oct 26, 2026 · @disc

Why agent prompts are a governance problem

In an agent framework, the system prompt is the closest thing you have to source code. It defines the agent’s role, what it may and may not do, how it calls tools, and when it stops. If it is vague, the agent’s behavior is unpredictable. If it is wrong, the agent is wrong at scale.

In our last post, Traditional vs. Agent Frameworks, we showed that agents move decisions from build time to runtime, and that “change the system prompt, no redeployment needed” quietly bypasses change management. This post goes one level down: how to write agent prompts well, and why a well-written prompt is still not a security control.

Good prompt engineering makes agents more reliable. It reduces hallucinated tool calls, malformed JSON and wasted steps. But a prompt is text read by a model that also reads untrusted text. An attacker’s instructions arrive through the same channel as yours.

So the rule from the last post holds, and gets sharper: use the prompt to guide behavior, and use controls outside the model to enforce it. Everything below separates the two.

Six practices, each with a security lens

1. System prompt structure

A good agent system prompt defines four things: the agent’s role, what it can and cannot do, how to format tool calls, and when to stop. Vague prompts produce unpredictable agents.

The security lens: the “cannot do” list is guidance, not a boundary. An injected instruction can talk the model out of it. Write the limits in the prompt so the agent behaves well, then enforce the same limits in code: a tool allowlist, a policy check before each action, and a step or cost budget that ends the run even if the model never decides to stop.

Also keep secrets out. API keys, internal URLs, database names and customer names do not belong in a system prompt. Assume every system prompt will eventually be extracted.

2. Tool usage instructions

Telling an agent when to prefer one tool over another, such as “use search_codebase before calling get_logs,” puts routing logic in the prompt instead of in graph edges. It works, and it makes agents more efficient.

The security lens: routing in the prompt is routing an attacker can rewrite. If the order matters for safety (check permissions before export, validate before delete), put it in the workflow graph or the tool itself, where a prompt cannot skip it. Keep prompt routing for efficiency, not for control.

Tool descriptions are prompts too. The agent reads them to decide what to call. A compromised MCP server or a careless edit to a description changes behavior just as a system prompt edit does.

3. Few-shot examples

One to three examples of a correct think-act-observe sequence sharply reduce hallucinated tool calls and malformed JSON. Models copy patterns well.

The security lens: they copy bad patterns just as well. An example that calls a tool with broad parameters, skips a check, or includes real customer data teaches the agent to do the same. Treat examples as part of the prompt: reviewed, version-controlled, built from synthetic data, and showing the safe path, including a refusal or an escalation.

4. Structured output

Asking the model to answer in JSON when it needs a tool lets the framework parse the tool name and parameters reliably. Unstructured text causes parse failures.

The security lens: valid JSON is not safe JSON. A well-formed call can still carry a path traversal, an injected SQL fragment, or an outside email address. Validate every field against a strict schema, check values against allowlists, and never pass model output straight to a shell, a query, or an eval. Structured output solves parsing, not trust.

5. Chain-of-thought elicitation

Asking the agent to reason before acting (“think step by step about what you know and what you still need”) reduces tool-call errors on complex tasks.

The security lens: the reasoning is useful evidence, but it is the model’s account of itself, not proof of what drove the action. Log the actions and the policy decisions as the record of truth. Reasoning text can also carry sensitive content from the context window, so decide deliberately whether to store it, for how long, and who can read it.

6. Iterative refinement

Treat system prompts as code: version-control them, run evaluations after every change, and iterate. Prompt drift is a real production risk for long-running agents.

The security lens: this is the practice that turns the other five into a governed system. Your evaluation suite should include security tests, not just quality tests: direct and indirect prompt injection, system prompt extraction, tool misuse, and data leakage. A prompt change that improves answer quality and weakens a refusal is a regression.

At a glance: what the prompt guides, and what must be enforced

PracticeWhat it improvesWhat it cannot guaranteeControl outside the prompt
System prompt structurePredictable role, scope and stoppingThat the agent obeys its own limits under injectionTool allowlist, policy check per action, step and cost budgets
Tool usage instructionsEfficient tool orderThat a safety-critical order is followedRequired sequences in the workflow graph or inside the tool
Few-shot examplesFewer hallucinated calls and JSON errorsThat copied patterns are safeReviewed, synthetic, versioned examples that model safe paths
Structured outputReliable parsing of tool callsThat the parameters are safeStrict schema validation, value allowlists, no direct exec
Chain-of-thoughtFewer errors on complex tasksThat the stated reasoning is what drove the actionAction and policy-decision logs as the record of truth
Iterative refinementQuality that improves over timeThat a change didn’t weaken securitySecurity evals, approval and release gates on every prompt change

The prompt threat model

Every agent prompt has two audiences: the model, and anyone who can put text in front of it. These are the threats that target the prompt layer, mapped to the OWASP Top 10 for LLM Applications (2025) and the OWASP Top 10 for Agentic Applications.

ThreatHow it worksOWASP mappingDefense
Direct prompt injectionA user tells the agent to ignore its instructionsLLM01; ASI01 goal hijackPolicy enforcement outside the model; refusal tests in evals
Indirect prompt injectionInstructions hidden in a document, web page, email, ticket or log the agent readsLLM01; ASI01Label and delimit untrusted content; least privilege for agents that read external data
System prompt leakageThe agent is coaxed into revealing its instructions, and any secrets in themLLM07No secrets in prompts; assume extraction; credentials in a vault
Tool description poisoningA malicious or modified MCP tool description steers the agentASI04 supply chain; ASI02 tool misuseApproved tool registry, pinned versions, review of description changes
Few-shot and memory poisoningBad examples or poisoned memory teach unsafe patternsASI06 memory and context poisoningVersioned examples; provenance and write controls on memory
Improper output handlingValid JSON carries malicious parameters into a shell, query or APILLM05; ASI05 code executionSchema and value validation; sandboxing; no eval of model output
Excessive agencyA well-intended prompt is paired with broad tools and credentialsLLM06; ASI03 privilege abuseLeast agency, scoped short-lived credentials, approval for high-impact actions
Prompt driftSmall edits and model updates slowly shift behaviorASI10 rogue agentsBaseline evals, version pinning, drift monitoring

Two lessons from the Evidence Lifecycle post apply directly. First, log content is untrusted input: an agent that summarizes logs can be injected through a file name or a ticket. Second, an agent must never control the logging that records it, or a successful injection can erase its own trail.

No prompt makes an agent injection-proof. Delimiters, instruction hierarchies and “never follow instructions in documents” lines reduce the success rate; they do not close the hole. Design as if the injection will eventually succeed, and limit what it can reach when it does.

Governing prompts like code

“Treat system prompts as code” is good engineering advice. It is also what your auditors already expect, because the frameworks do not care whether a change is written in Python or English.

Governance needISO/IEC 42001ISO/IEC 27001EU AI ActNIST AI RMF
Prompts as controlled documentsCl. 7.5 documented information; A.6.2.7 technical documentationCl. 7.5; A.5.37 documented operating proceduresArt. 11 technical documentation (high-risk)GOVERN 1.4 documented processes
Change control for prompt editsA.6.2.5 deployment; Cl. 6.3 planning of changesA.8.32 change managementArt. 12 logging across the lifetimeMANAGE 4.1 post-deployment monitoring
Testing before releaseA.6.2.4 verification and validationA.8.29 security testing in developmentArt. 15 accuracy, robustness, cybersecurityMEASURE 2 evaluation of trustworthiness
Secure prompt designA.6.2.3 design documentationA.8.28 secure codingArt. 15MAP 2 categorize the AI system
Disclosure to usersA.8 information for interested parties—Art. 50 transparencyGOVERN 4 culture and communication

In practice, that means four things:

  • One owner per prompt. Every production system prompt, tool description and few-shot set has a named owner, the same as a service.
  • One path to production. Prompt edits go through the same pull request, review and release record as code. Edits in a vendor console or an admin text box are blocked or logged and reviewed.
  • Eval gates. No prompt version ships without passing quality and security evaluations, with results kept as release evidence.
  • Reassessment triggers. A change to the agent’s role, tools, model or data sources reopens the AI risk assessment and, where relevant, the impact assessment.

The EU AI Act’s stand-alone high-risk obligations now start on 2 December 2027 under the AI Omnibus. An agent that shapes decisions about people will need to show which prompt version produced which outcome. That record cannot be rebuilt later.

Evidence: proving which prompt made which decision

When a customer disputes an agent’s action 18 months from now, “we use good prompts” will not help. You will need to show which prompt version was live, who approved it, how it was tested, and what the agent did under it.

EventWhat to keepSuggested retention
Prompt releaseVersion ID and hash for system prompt, tool descriptions and few-shot set; author; approver; release time5 years (application release records), or the longer decision-record period it supports
Evaluation runEval suite version, quality and security results, pass or fail, linked prompt versionSame as the prompt release it gates
Agent actionPrompt version hash live at the time, tool called, parameter hash, policy decision, outcomeBy tier: Tier A decisions often 3–7 years; operational logs 6 months to 3 years
Injection or guardrail detectionDetection rule, source of the content, action blocked or allowed1–3 years; longer if tied to an incident
Out-of-band prompt changeWho edited, where, before and after hashes, how it was caught5 years, as a change record

The key design choice is to log the prompt version hash with every action, not the prompt text. The full text lives once in version control. That keeps logs small, keeps customer data out of prompts in the log store, and still lets you reconstruct exactly what the agent was told.

These periods follow the retention approach in the Evidence Lifecycle post. They are starting points, not legal advice; have counsel confirm your final schedule.

Your 90-day plan

  1. Days 1–30: Find every prompt. Inventory the system prompts, tool descriptions and few-shot sets behind each production agent, including those edited in vendor consoles. Assign an owner to each. Remove any secrets you find and rotate them.
  2. Days 31–60: Put prompts under change control. Move all prompts into version control with review and release records. Build an evaluation suite that includes prompt injection, system prompt extraction, tool misuse and data leakage tests. Block or alert on out-of-band edits.
  3. Days 61–90: Move enforcement out of the prompt. For each “cannot do” line, add the matching control in code: tool allowlists, parameter validation, policy checks, budgets. Log the prompt version hash with every agent action. Then test: pick an agent action from last month and prove which prompt produced it in under an hour.

Pre-release checklist for an agent prompt

  • ☐ Role, allowed actions, forbidden actions and stop conditions are explicit
  • ☐ Every forbidden action is also blocked by a control outside the model
  • ☐ No secrets, internal URLs or real customer data in the prompt or examples
  • ☐ Safety-critical tool order is enforced in the workflow, not only in the prompt
  • ☐ Few-shot examples are synthetic and include a refusal or escalation
  • ☐ Tool-call JSON is validated against a strict schema before execution
  • ☐ Security evals passed: direct and indirect injection, extraction, tool misuse
  • ☐ Version, approver and eval results recorded for this release

Prompt engineering decides how well your agent behaves on a good day. Controls outside the prompt decide how much damage it can do on a bad one. You need both, and you need the evidence that you had both.

Need a hand?

DISC InfoSec helps B2B SaaS and financial services firms secure and govern AI agents under ISO/IEC 42001, ISO/IEC 27001, the EU AI Act and the NIST AI RMF. We led a virtual data room provider through ISO/IEC 42001 Stage 2 certification on the first attempt, including its MCP governance standard and AI log retention schedule.

Book a free 30-minute call at calendly.com/hd-deurainfosec, or email hd@deurainfosec.com. Comment PROMPT on the LinkedIn post and we will send you the pre-release prompt checklist and eval test set template.

Sources

  • The Evidence Lifecycle: Which Organizational Events to Log for Liability — and How Long to Keep Them — DISC InfoSec blog
  • Traditional vs. Agent Frameworks: Same Dimensions, Different Liabilities — DISC InfoSec blog
  • OWASP Top 10 for LLM Applications 2025 (LLM01, LLM05, LLM06, LLM07)
  • OWASP Top 10 for Agentic Applications (ASI01–ASI10)
  • ISO/IEC 42001:2023 and ISO/IEC 27001:2022, Annex A
  • Regulation (EU) 2024/1689 (EU AI Act), Articles 11, 12, 15, 50; AI Omnibus, Regulation (EU) 2026/1744
  • NIST AI 100-1, AI Risk Management Framework 1.0

Tags: Prompt Engineering

Leave a Reply

You must be logged in to post a comment. Login now.