Inspiration

Healthcare is increasingly adopting AI for tasks such as clinical summarization, triage, and decision support. But there is a fundamental privacy problem: how can healthcare professionals use powerful third-party AI models without exposing sensitive patient information?

I was inspired by a simple question:

What if you could prove that patient data was sanitized without revealing the patient data itself?

Traditional approaches either require trusting the application to sanitize data correctly or storing audit information that can itself expose sensitive context. I wanted to explore a different approach using Zero-Knowledge proofs: verify that sanitization requirements were satisfied while keeping the underlying clinical information private.


What it does

Midnight Veil is a privacy layer for clinical AI workflows.

A healthcare professional enters a clinical record containing sensitive information such as a patient's name, phone number, date of birth, or medical record number. Midnight Veil:

  1. Detects and removes PHI locally in the browser.
  2. Creates a sanitized version of the clinical prompt.
  3. Constructs a private audit witness containing information required for verification.
  4. Uses a Midnight Compact circuit to verify that no residual PHI remains.
  5. Records a verification state on the Midnight Testnet without storing the original clinical record.
  6. Sends only the sanitized prompt to an external LLM for AI-assisted clinical analysis.

The core idea is simple:

Prove it was sanitized.


How I built it

I built Midnight Veil as an end-to-end application combining client-side privacy processing, Zero-Knowledge verification, blockchain infrastructure, and AI.

I built the frontend using React, TypeScript, Vite, Tailwind CSS, and Lucide Icons.

The PHI sanitization layer runs locally in the browser and uses pattern-based detection to identify sensitive information such as names, phone numbers, dates, and medical record identifiers.

I implemented the verification logic using Midnight's Compact smart contract language. The circuit receives a private AuditWitness and verifies conditions such as:

residual_phi_count == 0

When PHI was detected, the system also verifies that the raw and sanitized prompt hashes are different.

I connected the application to the Midnight Testnet, where the verified compliance state is recorded. The sanitized prompt is then sent to an LLM through the OpenRouter API for structured clinical analysis.

The smart contract was successfully deployed to the Midnight Testnet.


Challenges I ran into

One of my biggest challenges was understanding how to design a useful Zero-Knowledge workflow without accidentally putting sensitive information on-chain.

It was tempting to treat the blockchain as a traditional audit database, but that would defeat the purpose of a privacy-preserving system. I therefore had to carefully separate what needs to be proven from what needs to remain private.

Another challenge was connecting the different layers of the application: browser-based PHI sanitization, private witness construction, Compact circuits, Midnight Testnet transactions, and the external AI inference layer.

I also had to think carefully about what my ZK circuit could actually prove. Rather than claiming that a blockchain transaction automatically makes an application HIPAA compliant, I focused on proving specific, verifiable sanitization conditions.


Accomplishments that I'm proud of

My biggest accomplishment was turning the idea of "prove privacy without revealing the data" into a working prototype.

I successfully:

  • Built a local PHI sanitization workflow.
  • Designed a private audit witness for sanitization verification.
  • Implemented verification logic in Midnight Compact.
  • Deployed the smart contract to the Midnight Testnet.
  • Connected the application to the Midnight blockchain.
  • Created an architecture where raw clinical data does not need to be written to the blockchain.
  • Integrated sanitized prompts with an external LLM.
  • Built an end-to-end workflow from clinical input → sanitization → ZK verification → blockchain receipt → AI analysis.

What I'm most proud of is that the project doesn't simply say:

"Trust me, I removed the PHI."

Instead, it explores how to provide:

"Cryptographic evidence that the required sanitization conditions were satisfied."


What I learned

I learned that building a privacy-preserving application is not just about encrypting data. The more important question is what information actually needs to be revealed, and what can remain private?

Working with Midnight helped me understand how Zero-Knowledge proofs can change the traditional relationship between privacy and verification. Normally, proving that something happened requires revealing evidence about what happened. ZK systems allow me to explore a different model: prove the condition without exposing the underlying data.

I also learned that designing the circuit is just as important as building the application around it. The guarantees of a ZK system depend on exactly what the circuit verifies.

Finally, I learned that privacy, AI, and blockchain have to be designed together. Adding blockchain to an existing healthcare application isn't enough; the privacy model needs to influence the architecture from the beginning.


What's next for Midnight Veil

Midnight Veil is currently a hackathon prototype, and I see several directions for future development.

Better PHI Detection

The current sanitization layer relies on deterministic pattern matching. I want to combine this with local NLP and Named Entity Recognition (NER) models to detect more complex forms of PHI.

Stronger Verification

I want to expand the Compact circuits to verify more sophisticated sanitization policies and provide stronger guarantees about what information can leave the local environment.

More AI Providers

The system could support multiple LLM providers while maintaining the same privacy layer between clinical data and external AI services.

Healthcare Integrations

I want to explore integrations with electronic health record (EHR) systems and clinical workflows so that privacy-preserving AI can become part of existing healthcare infrastructure rather than requiring a separate workflow.

Verifiable Compliance Reports

A future version could generate cryptographically verifiable compliance receipts that healthcare organizations can use during audits without exposing the underlying patient records.

Ultimately, I want Midnight Veil to explore a broader idea:

Sensitive data shouldn't have to be revealed just to prove that it was handled correctly.

Built With

Share this project:

Updates

Submission history