The Problem: LLMs and PHI in Production
Building large language model (LLM) features, especially over sensitive data like clinical text, presents a significant challenge: ensuring that the model never leaks Protected Health Information (PHI) or Personally Identifiable Information (PII) into its output. For developers working in regulated industries, this isn't just a best practice; it's a compliance necessity. When an LLM generates text, the risk of it inadvertently including patient identifiers, addresses, or other sensitive details is real. A build process that doesn't catch these leaks before deployment is a critical vulnerability.
The author of the new tool, a developer working with LLMs on clinical text, faced this exact problem. They sought existing solutions to guarantee that if an LLM output contained a patient identifier, the build process would fail. This would act as a hard stop, preventing potentially disastrous data leaks from reaching production environments.
Existing Solutions Fall Short
A survey of existing LLM evaluation libraries revealed a gap. Tools like autoevals, promptfoo, vitest-evals, and evalite either lacked specific functionality for detecting PHI/PII or relied on hosted APIs for evaluation. The latter approach is a non-starter for sensitive data. Sending patient data to a third-party API to check for leaks is fundamentally counter to the goal of protecting that data. It introduces its own set of risks and compliance headaches, making it an unacceptable solution for developers handling PHI.
This void in the market—the lack of a local, secure, and reliable method for detecting PHI leaks in LLM outputs during the build process—prompted the creation of a new solution.
Introducing phi-leak-guard: Local PHI Detection
To address this critical need, a new npm package, phi-leak-guard, has been developed. This is a zero-dependency TypeScript library designed specifically to detect PHI and PII within text. Its core function is to integrate seamlessly into a project's test suite, specifically targeting environments like Vitest and Jest. When the library identifies any sensitive information in the output, it triggers a failure in the test runner, thereby halting the build process.
The key advantage of phi-leak-guard is its entirely local operation. It requires no network connection and no external models. All detection logic runs within the developer's process. This means that sensitive data never leaves the local development environment, mitigating the risks associated with third-party API calls and ensuring compliance with data privacy regulations.

How it Works: Regex and Local Execution
phi-leak-guard operates using a robust set of regular expressions (regex) tailored to identify common patterns of PHI and PII. These patterns cover a wide range of sensitive data types, including but not limited to:
- Names
- Addresses
- Phone numbers
- Email addresses
- Social Security Numbers
- Dates of birth
- Medical record numbers
The library is designed for ease of integration. Developers can import the necessary functions and configure them to scan specific text outputs from their LLM applications. The configuration can be tailored to the specific types of PHI relevant to the project, allowing for fine-grained control over what constitutes a leak.
When a test is run that includes the phi-leak-guard checks, the library processes the LLM's output. If any of the defined regex patterns match within the text, the library throws an error. This error is caught by the test runner (Vitest or Jest), which then reports a test failure. This immediate feedback loop ensures that developers are alerted to potential data leaks before they can proceed further in the CI/CD pipeline.
The Surprising Absence of Similar Tools
What's genuinely surprising is not the existence of LLMs that can sometimes leak data, but the stark lack of readily available, locally executable tools specifically designed to prevent this during the build process. The market is flooded with LLM evaluation frameworks, but few, if any, prioritize the critical security and privacy aspect of PHI/PII detection within the development workflow itself. Most focus on accuracy, relevance, or tone, leaving a crucial gap for developers in sensitive domains. This oversight by the broader ecosystem highlights the value and necessity of tools like phi-leak-guard.
What This Means for Developers
For developers building applications that leverage LLMs, particularly those handling sensitive data, phi-leak-guard offers a practical and secure solution. Its local execution model eliminates the privacy concerns associated with cloud-based evaluation services. By integrating this library into their testing pipelines, developers can add a critical layer of defense against unintentional data leakage.
The package aims to be a simple yet effective safeguard. It doesn't aim to replace comprehensive LLM evaluation suites but rather to provide a focused, indispensable check for a specific, high-stakes risk. This allows teams to ship LLM-powered features with greater confidence, knowing that a fundamental data privacy check is in place at the earliest stage of their deployment pipeline.
Future Considerations and Open Questions
While phi-leak-guard provides a vital local check, its reliance on regex means it's only as good as the patterns it's configured with. The complexity of natural language and the evolving nature of LLM outputs mean that regex alone might not catch every edge case or sophisticated attempt to obfuscate sensitive data. What remains to be seen is how the library will evolve to incorporate more advanced detection methods, perhaps incorporating lightweight, local NLP models or fuzzy matching techniques, to further strengthen its defenses without compromising its core principle of local execution.
Furthermore, as LLMs become more integrated into diverse applications, the need for such targeted, security-focused developer tools will only grow. The success of phi-leak-guard could pave the way for a new category of security-centric libraries within the LLM development ecosystem.
