Skip to content

Naming injection_ml in Guard(scanners=) blocks every input #199

Open

Description

@chiruu12

Naming injection_ml in Guard(scanners=[...]) gives you a Guard that blocks everything.

Guard(scanners=["injection_ml"], model="tiny").scan("What is the capital of France?").risk_score
# 1.0

Guard(model="tiny").scan("What is the capital of France?").risk_score
# 0.0

Two injection_ml scanners get built. One is backed by TransformersSpanProvider and works. The other is backed by NullModelProvider, whose predict() returns None, so injection_ml.py:124 does list(prediction.spans) on None and raises AttributeError. base.py:48 catches it and emits a scanner_error finding with score=1.0, which becomes the risk for every input.

Nothing in the output says the scanner failed unless you are reading logs. The caller sees a confident block on plain text.

injection_ml.py:95 is the part that lets it through:

if self._model.loaded is False:
    self._model.load()

A provider that cannot produce a prediction gets asked for one anyway, and the None that comes back is trusted. Same result with scanners=["injection", "injection_ml"].

Two things worth deciding separately. Why a second scanner is constructed with a null provider when a real one is available, and whether NullModelProvider.predict should return an empty SpanPrediction or raise rather than returning None.

Activity

  1. cookieshop02 commented on Oct 18, 2026

    @cookieshop02
    Contributor

    Hi , I'd like to take this.

    My plan is two small changes:

    1. Stop the null-backed duplicate from being built: strip injection_ml from scanner_names in guard.py (the Guard already adds the provider-backed scanner itself).
    2. Defensive fallback: have NullModelProvider.predict return an empty SpanPrediction (spans=[], doc_score=0.0) instead of None, so it degrades to allow rather than raising.

    Plus a regression test: Guard(scanners=["injection_ml"], model="tiny").scan(...) → allow, not block.

    Does that approach work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageNot looked at yet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions