Skip to content

Conversation

@tjtanjin
Copy link

Title

fix(guardrails): support array-type content in Presidio pre-call hook

Description

Previously, the async_pre_call_hook in Presidio PII masking only handled messages with content as strings, and ignored messages where content was structured as a list of text blocks.

This caused PII in messages like the following to go unmasked:

{
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "My credit card is 4111-1111-1111-1111."},
        {"type": "text", "text": "My email is [email protected]."}
      ]
    }
  ]
}

Only messages with a simple string like this were being processed correctly:

{
  "messages": [
    {
      "role": "user",
      "content": "My credit card is 4111-1111-1111-1111."
    }
  ]
}

This PR adds proper handling for list-type content, ensuring PII detection and anonymization works consistently for both string and list message formats.

Pre-Submission checklist

Type

🐛 Bug Fix

Changes

  • Updated async_pre_call_hook in _OPTIONAL_PresidioPIIMasking to handle messages where content can be a list of text blocks instead of just a string.

  • Introduced minimal targets tracking to ensure PII-masked text is written back to the correct location.

  • Added new unit tests covering:

    • single text block inside a list
    • mixed string and list messages to verify target alignment
  • No changes to existing behavior for string-only messages.

@vercel
Copy link

vercel bot commented Oct 24, 2025

@tjtanjin is attempting to deploy a commit to the CLERKIEAI Team on Vercel.

A member of the Team first needs to authorize it.

@krrishdholakia
Copy link
Contributor

We do handle content list text blocks in presidio now -

elif isinstance(content, list):

@krrishdholakia
Copy link
Contributor

Let me know if I missed anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants