Implementation Guide

    Blocking Sensitive Data Hidden in System Prompts and Few-Shot Examples

    Treat the fully assembled prompt, not just the user message, as the object to inspect. Inventory every source of non-user content, define which data classes are allowed, redacted or blocked in each location, enforce that decision in the request path before the model call, and record each decision without storing the sensitive value. Externalizing secrets remains the primary fix. Runtime inspection is the backstop.

    Where sensitive data hides in non-user prompt content

    Most input controls watch what an end user types. A large share of what the model actually receives is written by someone else: developers, product teams, retrieval pipelines and tools. That content is reused across many interactions and is usually assumed to be trusted.

    System prompts are the first place to look. OWASP's guidance on system prompt leakage lists API keys, authentication keys, database names or credentials, user tokens, user roles and application permission structure as the kinds of content a system prompt may reveal. Prompt templates carry the same risk, because they are often copied from working prototypes that still contain connection strings or customer identifiers.

    Few-shot examples deserve separate attention. They are developer-authored in-context content, and they are often built from real tickets, emails or records because realistic examples perform better. The result is regulated personal data or proprietary business logic embedded in a store that few people review as a data-handling surface. Guidance on hidden context applies to them in the same way as it does to the system prompt.

    Retrieved and tool-supplied context adds more paths. RAG chunks can contain sensitive data that reached the index through oversharing upstream, such as unscoped drives or legacy permissions. Agents can pass credentials or file contents as tool arguments, and tool responses, fetched web pages and persistent memory all feed the same context window.

    Why input-only filtering and pre-deployment review fall short

    Input filters are positioned on the user message, so they never see a credential that a developer pasted into a system prompt. Even when a filter covers the whole request, it may treat the system prompt as trusted and skip it.

    Pre-deployment review and authoring conventions have a different weakness: they describe a point in time. Prompts are edited after release, templates are parameterized with values that change per call, and retrieved content differs on every request. A prompt that passed review last quarter may not match what is being sent today. Runtime inspection checks what is actually sent, each time.

    There is also a boundary problem. Language models make no architectural distinction between instructions and data, and prompt injection cannot be reliably prevented today. An instruction such as "never reveal the key" inside the system prompt is therefore not a control. OWASP's guidance is that hidden context should not be the sole security boundary for policy enforcement or content filtering, and that critical behavior should be enforced by independent, deterministic systems outside the model. Exposure through extraction or model output should be handled as a data-handling risk, not only as an injection risk.

    Define allow, redact and block per location

    Start with an inventory. For each source of non-user content, record the owner, the editing path and the systems that read it. Then set a policy per location. The per-location choices below are a design decision for your team, not a prescribed standard, but they follow from guidance that credentials and regulated data should not sit in hidden context.

    • System prompts and templates: Block credentials, API keys, tokens and connection strings. Block regulated personal data. Allow only documented, non-sensitive business instructions.
    • Few-shot examples: Block credentials and direct identifiers. Redact personal data where the example still works with placeholders. Require synthetic or de-identified examples for new additions.
    • Retrieved context: Redact regulated personal data the task does not need. Block secrets. Fix oversharing at the index source as well as at runtime.
    • Tool arguments and responses: Block credentials passed as arguments. Redact or block file contents that carry sensitive classes the tool does not require.
    • Proprietary business logic: Decide explicitly. Pricing rules or internal architecture details may be allowed to one model endpoint and blocked to another.
    • Ownership: Name an owner for each location and require a review path for edits, so policy changes are deliberate.

    Where to enforce, and how to detect

    Enforce in the request path, after the prompt is assembled and before it reaches the model or any third-party service. Enforcement earlier than assembly misses template parameters and retrieved content. Enforcement after the call is too late, because the data has already left. Agentic flows need the same coverage on tool calls and tool responses, not only the initial prompt.

    Normalize text before detection. Encoded or obfuscated content will pass a detector that only reads plain text, so decode first, then screen user input, external content and static prompt content as one layer.

    Choose detectors by what they find well. Pattern-based detection suits structured material such as key formats and token prefixes. Classifier-based detection suits personal data in free text, such as names and addresses inside a few-shot example. Context-aware detection helps separate a real customer identifier from a placeholder or a documentation sample. Each adds processing time to every request, so measure it against your latency budget and decide what happens on failure. For blocked data classes, failing closed is the safer default.

    Treat false positives as a measured metric. Track them per location, tune policy per location, and keep a route for developers to dispute a block. For redaction, remove the data from the content sent to the model. Masking it only in a display or log leaves it in the context the model can disclose.

    What each decision should record

    An auditor or incident responder needs to see what was inspected, which policy applied and what action was taken. The sources of guidance do not fix a schema, so define the fields yourself. A workable record includes the request identifier and timestamp, the calling application or identity, the prompt location inspected (system prompt, template, few-shot store, retrieved context, tool call), the data class detected, the detector used, the policy and policy version, the action taken (allow, redact or block), and the destination model or service.

    The record must not become a new leak. Reference detections by location, offset or a one-way fingerprint, and never store the credential or personal data itself. Log security-relevant metadata and decisions, not the unnecessary content.

    These records also support control mapping. They give evidence against the data privacy risk and the monitoring action for PII or sensitive data exposure in the NIST Generative AI Profile, and against OWASP's sensitive information disclosure, system prompt leakage and hidden context entries. Output-side checks in trusted application code complement this, since inspection of the prompt does not cover everything a model might generate.

    Where Trussed fits

    Trussed enforces policy in the execution path across models, agents, tools, MCP servers, AI sites and coding assistants. Decisions can be allow, redact, block, rate limit or escalate for human approval, applied to individual interactions and tool calls. Enforcement happens at runtime, not reviewed after the fact, and generates continuous audit-ready evidence for regulated enterprise teams. Trussed can be self-managed in the customer cloud, with configurable retention and data residency, which matters when evidence records themselves must stay inside your boundary.

    It is one way to implement the runtime layer described above. The inventory, the per-location data class policy and the ownership model are work your team needs to do whichever enforcement mechanism you choose.

    Inspection points in the request path

    Assemble

    System prompt, template, few-shot examples, retrieved and tool context, and the user message are combined.

    Inspect

    The full assembled prompt is normalized and checked against policy before it leaves your boundary.

    Decide

    Each detection results in allow, redact or block, based on data class and prompt location.

    Record

    The decision, policy and action are stored as evidence, without the sensitive value.

    Review your prompt content policy with a specialist

    Walk through your prompt locations, data classes and enforcement points, and see how runtime decisions become audit-ready evidence.

    Request a Demo
    Next step

    How does your AI governance program compare?

    See where your program has gaps in less than 2 minutes.