Implementation Guide

    How to Redact Account Numbers from Google Drive Files Before the Agent's Model Sees Them

    Redact account numbers in the tool-call response path: after the Drive connector or tool returns file content, and before that content enters the model's context. Inspect the extracted text, apply an allow, redact, or block decision under a defined policy, and record the decision as evidence. Redaction at the prompt layer or in later review happens after the model has already processed the values.

    Apply allow, redact, or block at the tool-call level

    1. 1

      1. Intercept the tool response

      Capture content returned by the Drive connector or MCP server before it is handed to the agent.

    2. 2

      2. Extract and normalize text

      Convert each file type to inspectable text, and flag files where extraction is incomplete.

    3. 3

      3. Evaluate the policy

      Run detection rules and thresholds, then select the action defined for each data class and workflow.

    4. 4

      4. Enforce the action

      Allow unchanged content, replace matches with a placeholder, or block the call and return a controlled message.

    5. 5

      5. Deliver only the permitted content

      The model receives the redacted or allowed output, never the original response.

    6. 6

      6. Write the evidence record

      Capture the decision at the moment of enforcement, not reconstructed later.

    Verify enforcement and retain audit-ready evidence

    • Timestamp, agent identity, tool, and the Drive file reference involved
    • Policy name and version that was evaluated
    • Detection categories matched and the count of matches, not the values
    • Action taken: allow, redact, block, or escalate
    • A representation of what the model received, such as the redacted output or a reference to it
    • Extraction or inspection status, including cases where content could not be reliably inspected

    Where redaction can be applied between Drive and the model

    An agent typically reaches Drive content through a connector, a direct API call, an MCP server, or a file export step. Whichever route is used, the result is returned to the agent runtime as a tool response and then placed into the model's context. That gives four places where redaction could be applied, and they differ in what they can guarantee.

    The useful question for each is simple: can raw account numbers still reach the model if this control is missing, misconfigured, or bypassed?

    • At rest in Drive: Cleans the stored file. It operates on documents rather than on the agent's retrieval path, so it does not cover files not yet cleaned, new uploads, or content the agent assembles from several files.
    • In the connector: Close to the source, but it depends on each connector or MCP server implementing inspection correctly. Third-party tools differ, and agents tend to trust them implicitly.
    • In the tool-call response: Sits between the tool and the agent, applies one policy to every tool, and acts before content reaches context. This is the preferred enforcement point.
    • At the prompt layer: Acts after the agent has assembled context. Useful as a secondary check, but it is late, and values may already sit in memory or intermediate state.

    Why enforcement has to happen before model ingestion

    Agents hold working state in short-term context windows and may keep information in longer-term memory stores. A value that reaches context can therefore outlive the call that retrieved it, depending on how the agent is built. Redacting afterward, whether in the prompt layer or in post-hoc review, leaves a window in which the model has already processed the sensitive value.

    Tool responses should also be treated as untrusted content. Agents often load third-party tools and MCP endpoints and trust them without strong verification, so an inspection step that does not depend on the tool behaving well is the more defensible design.

    Two limits apply. Redaction removes information, but it does not on its own provide formal privacy guarantees, and selective redaction can reduce data accuracy. Treat it as one exposure-reduction control. Pair it with data minimization: do not retain or expose account numbers where there is no essential business need.

    Define the detection and redaction policy

    Detection quality determines how much the policy can be trusted. No single technique is sufficient, so combine them and decide explicitly how much noise you will tolerate.

    • Start with format patterns: Use regular expressions for the account number formats your business actually holds, such as bank, policy, claim, and customer identifiers. Regex is fast but cannot perform logical checks such as checksums.
    • Add validation where the format allows: If a format carries a check digit, validate it to cut false positives. Confirm per format whether one exists before relying on it.
    • Use contextual keywords carefully: Terms such as account, policy, or routing near a digit string raise confidence. Proximity rules depend on being tuned correctly and can produce considerable noise if left unmanaged.
    • Set thresholds: A count-based threshold decides how many matches trigger an action. Choose values by testing against representative files, not by default.
    • Consider ML classification: Machine learning can improve categorization by learning from data patterns, but it needs significant setup and management.
    • Map each data class to an action: Decide which classes are redacted, which cause the whole tool call to be blocked, and which are allowed for a named workflow.

    Handle file types and format edge cases

    Inspection runs on text, so the first task is getting reliable text out of each file type. Docs and Sheets usually yield text directly, but Sheets add structure: an account number may sit in a cell whose column header, not adjacent text, supplies the context. Keyword proximity rules written for prose can miss that, so test header-aware rules. Also check that spreadsheet formatting does not split or reformat digits, for example through scientific notation or leading zeros dropped.

    PDFs may contain a text layer, scanned pages, or both. Scanned images and image-only PDFs require optical character recognition before any pattern can match, and OCR errors can turn a valid number into one that fails a checksum or pattern. Treat the false-negative risk here as higher and measure it separately from native-text files.

    The most important edge-case decision is what happens when content cannot be reliably inspected. If extraction fails or OCR confidence is low, the safe default for sensitive workflows is to block the response or escalate it for review, not to pass it through. Whatever you choose, make it an explicit policy rule so the behavior is consistent and recorded.

    Finally, test with realistic data per file type: numbers split across lines, numbers with spaces or hyphens, numbers in headers and footers, and non-sensitive digit strings that resemble account numbers.

    Retrieval path with an in-path enforcement point

    Drive file

    Doc, Sheet, PDF, or scanned image containing account numbers.

    Connector or tool call

    Extracts and returns file content to the agent runtime.

    Policy decision

    Content is inspected, then allowed, redacted, or blocked.

    Model context

    Receives only the content the policy permitted.

    Evidence record

    Policy version, action, and counts, without the original value.

    Enforce account number policy before content reaches the model

    See how in-path enforcement applies allow, redact, or block decisions to tool call content and produces audit-ready evidence.

    See How Evidence Is Produced