exactly as first element? The instruction: "Keep the provided opening
EXACTLY as the first element. Do not delete the direct answer." But the opening block given is
EXACTLY as the first element. Do not delete the direct answer." Possibly they refer to the opening
from existing thin body? The existing thin body after the heading includes a
Catch unsafe AI medical advice before a patient reads it.
. So we must keep thatexactly as first element after the heading? The opening block is the heading; then we must keep the provided opening
exactly as the first element (i.e., after heading). So we need to output:
Catch unsafe AI medical advice before a patient reads it.
Then continue with rest. We must not include doctype, html/head/body, no FAQ section, no Related, no CTA. Also must not include the existing thin body's FAQ etc. We need to replace with our thickened content. We need 6-8we keep. We need to produce a thickened HTML fragment. Let's plan sections: After opening
, we can have:
...
Then maybeI 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.
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.
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.
We could add a list under each h3 maybe. But we need lists somewhere; we can add a list of rule sources. Now section 3: Core componentsThe 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.
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.
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.
We could add a table here: maybe a table of component vs responsibility. Let's add a table after the h3s.| 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 |
I curate rules from three main categories:
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.
Now section 6: What this is NOT We need honesty section: no guarantee / 100% / never miss. We'll write: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.
Now section 7: References We needI 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.
Check: "I collect safety rules from trusted sources such as drug interaction databases, clinical guidelines, and regulatory advisories." Words: "I", "collect", "safety", "rules", "from", "trusted", "sources", "such", "as", "drug", "interaction", "databases,", "clinical", "guidelines,", "and", "regulatory", "advisories." OK. "Each rule is expressed as a simple pattern: for example, “if the text mentions ‘warfarin’ and also mentions ‘aspirin’ without mentioning ‘INR monitoring’, flag”." Words: "Each", "rule", "is", "expressed", "as", "a", "simple", "pattern:", "for", "example,", "“if", "the", "text", "mentions", "‘warfarin’", "and", "also", "mentions", "‘aspirin’", "without", "mentioning", "‘INR", "monitoring’,", "flag”." OK. "I store these patterns in a JSON file that the service loads at start‑up." Words: "I", "store", "these", "patterns", "in", "a", "JSON", "file", "that", "the", "service", "loads", "at", "start‑up." OK.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.
Check: "When the AI returns a response, the service splits the text into sentences and runs each sentence through the pattern matcher." Words: "When", "the", "AI", "returns", "a", "response,", "the", "service", "splits", "the", "text", "into", "sentences", "and", "runs", "each", "sentence", "through", "the", "pattern", "matcher." OK. "The matcher uses regular expressions that are pre‑compiled, so the evaluation takes a few milliseconds per sentence." Words: "The", "matcher", "uses", "regular", "expressions", "that", "are", "pre‑compiled,", "so", "the", "evaluation", "takes", "a", "few", "milliseconds", "per", "sentence." OK. "I keep the matcher stateless so multiple requests can be processed in parallel." Words: "I", "keep", "the", "matcher", "stateless", "so", "multiple", "requests", "can", "be", "processed", "in", "parallel." OK.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.
Check: "If any sentence matches a rule, the service creates a flag object that includes the rule ID, the matched sentence, and a suggested action." Words: "If", "any", "sentence", "matches", "a", "rule,", "the", "service", "creates", "a", "flag", "object", "that", "includes", "the", "rule", "ID,", "the", "matched", "sentence,", "and", "a", "suggested", "action." OK. "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." Words: "The", "UI", "can", "choose", "to", "show", "the", "flag", "beside", "theCatch unsafe AI medical advice before a patient reads it.