Security and PII validation using Instructor’s validators
We need to ensure no PII ever leaves our environment in an LLM response. Why Instructor is changing how we use LLM outputs to help with security? Can I use Pydantic validators to block specific strings or patterns before the data is even returned to the application?
2026-01-10 in Cyber Security by Patrick Sullivan
| 8176 Views
All answers to this question.
This is one of the most underrated security features of the library. Because Instructor uses Pydantic, you can write custom validator functions that run instantly after the LLM generates a response but before your app logic touches it. For example, you can write a validator that checks for social security numbers or credit card patterns using regex. If the LLM accidentally includes them, the validator fails, and Instructor can either redact the info or tell the model to "rewrite the response without the sensitive data." This gives you a programmatic "firewall" that is much more reliable than just asking the model to "be safe" in the system prompt.
Answered 2026-01-15 by Margaret Hall
Does this validation happen locally on our server, or does the data have to go back to the LLM provider for the "re-asking" part to work?
Answered 2026-01-18 by Gregory Adams
-
Gregory, the validation itself happens entirely on your local server. If the validation passes, the data never goes back. If it fails and you have retries enabled, only then does a "correction prompt" get sent back to the LLM. For high-security environments, you can even configure Instructor to just "throw an error" on a validation failure rather than retrying, ensuring that you have absolute control over what data is accepted into your system.
Commented 2026-01-25 by Vincent Brooks
It's essentially "Shift Left" security for AI. You're catching data leaks at the schema level instead of at the database level.
Answered 2026-02-10 by Sandra Martinez
-
Great point, Sandra. Patrick, using Instructor for your security layer is a very "2026" way of handling AI compliance. It’s clean and effective.
Commented 2026-02-20 by Patrick Sullivan
Write a Comment
Your email address will not be published. Required fields are marked (*)

