by MedGuard
What is MedGuard?
MedGuard is a safety layer that screens patient-facing AI output for unsafe medical advice before a person ever reads it.
Why a safety layer for patient-facing AI
Patient-facing AI can give confident, fluent answers that are still wrong or dangerous. A safety layer catches those before they reach a person, turning silent risk into a visible, reviewable flag.
How MedGuard works
Rule ingestion
I collect safety rules from trusted sources such as drug interaction databases, clinical guidelines, and regulatory advisories. Each rule is expressed as a simple pattern: for example, “if the text mentions ‘warfarin’ and also mentions ‘aspirin’ without mentioning ‘INR monitoring’, flag”. I store these patterns in a JSON file that the service loads at start-up.
Real-time validation
When the AI returns a response, the service splits the text into sentences and runs each sentence through the pattern matcher. The matcher uses regular expressions that are pre-compiled, so the evaluation takes a few milliseconds per sentence. I keep the matcher stateless so multiple requests can be processed in parallel.
Flagging and blocking
If any sentence matches a rule, the service creates a flag object that includes the rule ID, the matched sentence, and a suggested action. The UI can choose to show the flag beside the original text, replace the sentence with a safe placeholder, or block the entire message and show a fallback warning. I log every flag for later audit.
Core components
Rule engine
The rule engine is the heart of MedGuard. It loads rule files, compiles patterns, and provides a simple API: evaluate(text) -> list of flags. I wrote it in Python because the ecosystem offers good regex performance and easy packaging.
API wrapper
Around the rule engine I built a thin HTTP wrapper that accepts JSON payloads with the AI response and returns JSON with flags or a cleaned version. The wrapper enforces a maximum request size of 64 KB to avoid abuse.
UI integration kit
To help developers add MedGuard to their apps I provide a small JavaScript snippet that intercepts fetch calls to the AI endpoint, sends the response to the MedGuard API, and updates the DOM based on the returned flags. The snippet is under 5 KB gzipped.
Component | Responsibility Rule engine | Loads, compiles, matches safety patterns API wrapper | Handles HTTP, enforces limits, returns flags UI kit | Calls API, shows warnings, allows overrides
Safety rule sources
I curate rules from three main categories:
- Drug safety: labels from FDA-approved prescribing information, focusing on dosage limits, contraindications, and required monitoring. - Condition-specific guidance: guidelines from professional societies (e.g., American Heart Association for chest pain, American Diabetes Association for hypoglycemia). - Regulatory advisories: alerts from agencies such as the CDC or WHO about emerging risks.
Each rule is written as a plain-text pattern that can be evaluated with regular expressions. For example, a rule for NSAID use in patients with kidney disease might look like: “if the text mentions ‘ibuprofen’ and also mentions ‘creatinine > 1.5’ without mentioning ‘dose adjustment’, flag”.
I keep the rule set versioned in a Git repository so any change can be reviewed and rolled back if needed. The version number is included in every API response so downstream systems know which rule set was applied.
What this is NOT
MedGuard does not promise to catch every possible unsafe suggestion. The rule-based approach can miss novel phrasing or context-dependent hazards that are not captured in the current rule set. I do not claim 100% coverage, and I advise clinicians to treat the output as a decision-support aid, not a replacement for professional judgment.
It is not a diagnostic tool. The system does not attempt to infer a patient’s condition or recommend a treatment plan; it only checks the AI-generated text against known safety patterns.
It does not replace the need for a qualified clinician to review high-risk messages. If a flag appears, the clinician should still evaluate the situation and make the final call.
Frequently asked questions
What is MedGuard?
Catch unsafe AI medical advice before a patient reads it.
References
- Plain language / decision-support framing - FTC advertising guidance
Try MedGuard
Related reads
- How does MedGuard check health AI? - The LX AI Micro-SaaS Topic Matrix
Decision-support only. Not medical advice, a diagnosis, or an FDA device clearance.