Skip to content

feat: Add pii_detection check#2408

Open
harsh21234i wants to merge 2 commits intoGiskard-AI:mainfrom
harsh21234i:pii-detection-check
Open

feat: Add pii_detection check#2408
harsh21234i wants to merge 2 commits intoGiskard-AI:mainfrom
harsh21234i:pii-detection-check

Conversation

@harsh21234i
Copy link
Copy Markdown

@harsh21234i harsh21234i commented Apr 16, 2026

#2374

Summary

Adds a new built-in pii_detection check to giskard-checks for
detecting personally identifiable information in model outputs.

What changed

  • added PIIDetection under giskard.checks.judges
  • added prompt template judges/pii_detection.j2
  • exported the new check from public package entrypoints
  • added tests for:
    • structured PII detection in pattern mode
    • contextual PII detection in llm mode
    • hybrid mode short-circuiting on regex hits
    • category filtering
    • serialization

Behavior

Supported modes:

  • pattern
  • llm
  • hybrid

Structured categories currently handled with regex:

  • email
  • phone
  • ssn
  • credit_card
  • ip_address

Contextual categories handled through LLM evaluation:

  • name
  • address
  • medical_info
  • financial_info

hybrid mode first checks structured PII via regex and only falls back to
the LLM for contextual categories when needed.

Validation

Ran:

uv run --all-packages --group dev pytest libs/giskard-checks/tests/
builtin/test_pii_detection.py libs/giskard-checks/tests/builtin/
test_toxicity.py

Result:

- 20 passed

## Related

Closes #2374
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the PIIDetection check, which identifies personally identifiable information in AI responses using regex patterns, LLM evaluation, or a hybrid approach. Feedback focuses on refining the regex patterns for SSNs, credit cards, and IP addresses to reduce false positives, as well as correcting a logic error in the output resolution process that could cause runtime failures when using default settings.

Comment thread libs/giskard-checks/src/giskard/checks/judges/pii_detection.py Outdated
Comment thread libs/giskard-checks/src/giskard/checks/judges/pii_detection.py Outdated
Comment thread libs/giskard-checks/src/giskard/checks/judges/pii_detection.py Outdated
Comment thread libs/giskard-checks/src/giskard/checks/judges/pii_detection.py Outdated
@harsh21234i
Copy link
Copy Markdown
Author

Addressed the review feedback by fixing trace fallback for output extraction and tightening the SSN, credit-card, and IPv4 regexes. Added tests for the stricter pattern behavior and reran the targeted giskard- checks suite successfully.
Happy To Contribute More !!!

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

1 participant