Skip to main content

VLM-Guard

Medical Verification Layer for Multimodal LLMs.

VLM-Guard is a framework for building rule-based verification layers that catch physically impossible, biologically inconsistent, or logically contradictory outputs from multimodal LLMs — before they reach the end user.

from vlm_guard import GuardrailEngine, BaseRule, RuleResult

# 1. Define a rule
class NoMalariaInTissueRule(BaseRule):
    name = "sample_type_check"
    description = "Malaria requires blood smear, not tissue biopsy"

    def condition(self, analysis, context):
        return (
            analysis.label == "Malaria"
            and "tissue" in context.get("sample_type", "").lower()
        )

    def action(self, analysis, context):
        analysis.label = "Unclear"
        analysis.confidence = "Low"
        return analysis, RuleResult(
            action_taken=True, action_type="block",
            message="Malaria cannot be diagnosed on tissue biopsy"
        )

# 2. Register and run
engine = GuardrailEngine()
engine.register(NoMalariaInTissueRule())

final = engine.apply(analysis, context={"sample_type": "Tissue Biopsy"})

Why

Multimodal LLMs hallucinate confidently. In medical AI, a "hallucination" isn't a funny caption — it's a biologically impossible diagnosis that could lead to real-world harm.

VLM-Guard gives you a composable, auditable rule engine to:

  • ✅ Block impossible outputs (malaria in a tissue biopsy)
  • ✅ Correct misclassifications (flagellate in blood → trypanosomiasis)
  • ✅ Promote clear patterns when the LLM is uncertain
  • ✅ Flag ambiguous findings for human review
  • ✅ Audit every modification with before/after snapshots

Installation

pip install vlm-guard

For image processing extras:

pip install vlm-guard[image]

Quick Start

1. Define your analysis schema

from vlm_guard import Analysis

result = Analysis(
    label="Malaria",
    confidence="High",
    evidence="Ring forms observed inside RBCs",
    findings="Multiple ring-stage parasites in thin blood smear",
    recommendation="Confirm species with PCR",
    metadata={"severity": "Moderate (++)", "species": "P. falciparum"}
)

2. Build rules

Rules have two methods:

  • condition(analysis, context) — should this rule fire?
  • action(analysis, context) — what to do when it fires
from vlm_guard import BaseRule, RuleResult

class SizeCheckRule(BaseRule):
    name = "size_check"
    description = "Rejects morphometrically impossible descriptions"

    def condition(self, analysis, context):
        text = (analysis.findings + " " + analysis.evidence).lower()
        return "7 μm" in text and "macrophage" in text

    def action(self, analysis, context):
        analysis.label = "Unclear"
        analysis.confidence = "Low"
        return analysis, RuleResult(
            action_taken=True, action_type="block",
            message="RBC-sized structures in macrophage cannot be amastigotes (2-4 μm)"
        )

3. Run the guardrail engine

from vlm_guard import GuardrailEngine

engine = GuardrailEngine()
engine.register(SizeCheckRule())

final, audit = engine.apply_with_audit(result, context={"sample_type": "Bone Marrow"})
print(audit.summary())
# [{"rule": "size_check", "action": "block", "message": "...", "modified": ...}]

4. End-to-end pipeline

from vlm_guard import VLMGuardPipeline
from vlm_guard.llm.parsing import parse_to_analysis
from vlm_guard.image.enhance import ImageEnhancer, EnhancementStrategy

pipeline = VLMGuardPipeline(
    model_fn=my_llm_inference_fn,      # any Callable[[Image, str], str]
    parser_fn=parse_to_analysis,        # built-in JSON parser
    guardrail_engine=engine,
    enhancer_fn=ImageEnhancer(EnhancementStrategy.HIGH_CONTRAST),
)

result = pipeline.run(image, prompt, context={"sample_type": "Blood Smear"})
print(result.analysis.label)       # final label after guardrails
print(result.audit.summary())      # everything that changed

Architecture

                     +-----------+
                     |   Image   |
                     +-----+-----+
                           |
                           v
                +----------+----------+
                |  Enhancement (opt)  |
                +----------+----------+
                           |
                           v
                +----------+----------+
                |  Multimodal LLM     |
                +----------+----------+
                           |
                           v
                +----------+----------+
                |  JSON Parser         |
                +----------+----------+
                           |
                           v
                +----------+----------+
                |  Guardrail Engine    |
                |  +-- Rule 1 (block)  |
                |  +-- Rule 2 (flag)   |
                |  +-- Rule 3 (correct)|
                |  +-- Audit Trail     |
                +----------+----------+
                           |
                           v
                +----------+----------+
                |  Final Analysis      |
                +---------------------+

Plugin System

Domain-specific rule packs can be distributed as plugins:

from vlm_guard import GuardrailEngine
from my_plugin import register_my_rules

engine = GuardrailEngine()
register_my_rules(engine)
from vlm_guard.plugins import ntd_microscopy

engine = GuardrailEngine()
ntd_microscopy.register_ntd_rules(engine)

Built-in plugin:

  • vlm_guard.plugins.ntd_microscopy — 12 rule classes for Neglected Tropical Disease microscopy (migrated from NTD-Assist)

Rules

VLM-Guard supports four rule types:

Type Use Case Example
Block Prevent impossible outputs Malaria on tissue biopsy → Unclear
Correct Fix misidentifications Flagellate in macrophage → Leishmaniasis
Promote Upgrade confidence when strong signal Amastigote + tissue → Leishmaniasis
Flag Lower confidence / append to recommendation "Ambiguous morphology, manual review suggested"

Extending

VLM-Guard is model-agnostic. The pipeline accepts any Callable[[Image, str], str]:

  • HuggingFace transformers models
  • OpenAI / Anthropic API clients
  • Local GGUF inference
  • Mock models for testing

License

MIT

Citation

@software{vlmguard2026,
  title = {VLM-Guard: Verification Layer for Multimodal LLMs},
  author = {Fakhry, Mohamed},
  year = {2026},
  url = {https://github.com/MohamedFakhry2007/vlm-guard}
}

Metadata

Release files for vlm-guard 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vlm-guard 0.2.1
File Size Uploaded Provenance Actions
vlm_guard-0.2.1.tar.gz 36.7 kB With provenance Details for vlm_guard-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vlm-guard 0.2.1
File Interpreter ABI Platform Actions
vlm_guard-0.2.1-py3-none-any.whl Python 3 none any Details for vlm_guard-0.2.1-py3-none-any.whl

Total release size: 72.5 kB

Release files / vlm_guard-0.2.1.tar.gz

Download URL vlm_guard-0.2.1.tar.gz
Size 36.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b7f49cd42bf4d1213584476c546637405255f13a86109dda01b162d279890412
BLAKE2b-256 checksum
How to use checksums
7d44fc474ccdad772b742133da181d7b0c86bac2bbebcc5c38fb4cb84d2b27a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / vlm_guard-0.2.1-py3-none-any.whl

Download URL vlm_guard-0.2.1-py3-none-any.whl
Size 35.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74e7578ddbd81581710c7941230652954d183c3cdffd82454becc6b89dfa211c
BLAKE2b-256 checksum
How to use checksums
f1e9640a0338a3341c8ae6c6db8098b41db48f7159e47178c5de30d2fa795573
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for vlm-guard 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vlm_guard-0.2.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page