Safety
Guardrails
Framework
Open Source

VLM-Guard

A composable rule-based verification layer that catches physically impossible, biologically inconsistent, or logically contradictory LLM outputs before they reach the end user.

The Clinical Problem

"Multimodal LLMs hallucinate confidently. In medical AI, a hallucination isn't a bug report — it's a patient safety incident."

How It Works

1. Image Enhancement

  • →Domain-specific preprocessing (Giemsa contrast, X-ray normalization)
  • →Quality checks: blur, exposure, grayscale validation
  • →Configurable enhancement strategies (HIGH_CONTRAST, etc.)

2. Multimodal LLM Inference

  • →Model-agnostic: works with any Callable[[Image, str], str]
  • →HuggingFace, OpenAI, Anthropic, Google, local GGUF, or mock
  • →Structured JSON prompt with reasoning_steps + answer schema

3. Structured Output Parsing

  • →parse_reasoning_steps() extracts typed claim objects
  • →Each claim has: type, observation, confidence, location
  • →Pydantic-based Analysis schema with validation

4. Guardrail Engine

  • →Composable rule engine: register any number of rules
  • →BaseRule: per-claim validation (condition + action)
  • →CrossClaimRule: multi-claim consistency checks

5. Audit Trail & Result

  • →Every rule firing recorded with before/after snapshots
  • →AuditTrail.to_dict() for compliance/regulatory review
  • →Final result: structured Analysis with validation status

Safety & Trust

Every output passes through deterministic, auditable guardrails before reaching the user. No black boxes. No unseen failures.

BlockImpossible Output Prevention

Catches physically or biologically impossible claims (e.g., 'malaria in tissue biopsy') and blocks them, replacing with an appropriate uncertainty response.

CorrectMisidentification Fix

Automatically corrects known misidentification patterns (e.g., flagellate in macrophage → promote to Leishmaniasis diagnosis).

PromoteConfidence Promotion

When strong diagnostic signals are present but the LLM is uncertain, promotes the finding to increase confidence and ensure it reaches the clinician.

FlagHuman Review Signal

Lowers confidence and appends a recommendation for human review when the system detects borderline or ambiguous findings.

About This Project

VLM-Guard was built from the ground up to solve a fundamental problem: LLMs in medicine are probabilistic, but patient safety cannot be. Rather than trying to make models hallucinate less (fine-tuning, prompting tricks), VLM-Guard adds a deterministic post-generation verification layer. Every output is parsed into structured claims, validated against rule-based guardrails, and either accepted, corrected, or blocked — with a full audit trail of every decision. This is the safety substrate powering HeartSafe RAG, NTD-Assist, and MedVision Assist.

Key Features

  • Composable rule engine with 4 action types (Block / Correct / Promote / Flag)
  • Two rule classes: BaseRule (per-claim) and CrossClaimRule (multi-claim consistency)
  • Full audit trail serializable via AuditTrail.to_dict()
  • Built-in ImageEnhancer with domain-specific strategies
  • Image quality checks: blur, exposure, grayscale validation
  • Plugin system for domain-specific rule packs (NTD microscopy, cardiology, radiology)
  • Model-agnostic: any multimodal LLM or text-only LLM
  • Pydantic-based Analysis schema with typed validation

Impact

  • →Powers safety for 3 production clinical AI applications
  • →Published to PyPI: pip install vlm-guard
  • →Deterministic safety layer — not probabilistic, not fine-tuning dependent
  • →Full audit trail enables regulatory compliance and post-hoc review
  • →Plugin architecture enables community-contributed domain rule packs

Technology Stack

Python 3.10+
Pydantic 2.x
Pillow
PyTorch (optional)
pytest
fpdf (optional PDF gen)

Building a clinical AI system of your own?

The Clinical AI Reliability Audit applies the same kind of evaluation and safety engineering to your system: architecture and risk discovery, evaluation and root cause analysis, and targeted engineering improvements. For a working healthcare app built with AI coding tools, the Clinical Prototype Readiness Review is the smaller starting point.

Related Projects

This project is part of a connected ecosystem. Each piece reinforces the same mission: safe, trustworthy clinical AI.

Mohamed Fakhry

Physician-Engineer working on clinical AI architecture, engineering and reliability, and on healthcare software that has to hold up in real-world use.

Physician-Engineer (M.B.B.Ch.) • Clinical AI Engineering • Former CEO

Connect

Building reliable, production-grade healthcare AI systems.

© 2026 Mohamed Fakhry. All rights reserved.

Built with care using modern web technologies