Skip to content

verification

Assert that Output Protection (OP) actually took effect in vLLM, and refuse to serve if it did not.

The failure mode that matters here is not a crash, but a server that starts via vllm serve, skips OP, and thus returns plaintext outputs.

This module closes that gap:

  • inject_verification wraps build_app and asserts every OP invariant against the application that was actually built, raising before the server accepts a single request.
  • Loads the declared vllm.general_plugins entry points exactly as vLLM does, but without vLLM's except Exception around the import, and asserts the process-wide invariants. This runs at image build time and catches the one case no runtime hook can: a plugin module that fails to import, which vLLM catches, logs, and skips at runtime.

Warning

Under almost no circumstances should you need to import this module directly. If stainedglass_output_protection is installed, vLLM loads it automatically via the vllm.general_plugins entry point.

Functions:

Name Description
assert_output_protection_active

Verify that Output Protection is active on a freshly built FastAPI application.

inject_verification

Assert that Output Protection is active on the application.

output_protection_plugins

Find this package's vllm.general_plugins entry points.

self_check

Load the declared vLLM plugins the way vLLM does and assert the process-wide patches are applied.

assert_output_protection_active

assert_output_protection_active(
    app: FastAPI, cli_args: Namespace
) -> None

Verify that Output Protection is active on a freshly built FastAPI application.

Parameters:

Name Type Description Default

app

FastAPI

The application returned by vLLM's build_app.

required

cli_args

Namespace

The parsed command-line arguments the application was built from.

required

Raises:

Type Description
RuntimeError

If any Output Protection invariant does not hold.

inject_verification

inject_verification(
    build_app_func: BuildAppFunc,
) -> middleware.BuildAppFunc

Assert that Output Protection is active on the application.

Parameters:

Name Type Description Default

build_app_func

BuildAppFunc

Function that builds the vLLM OpenAI-compatible FastAPI application.

required

Returns:

Type Description
middleware.BuildAppFunc

A new function with the same signature as build_app_func that verifies the built application before returning it.

output_protection_plugins

output_protection_plugins() -> list[
    importlib.metadata.EntryPoint
]

Find this package's vllm.general_plugins entry points.

Returns:

Type Description
list[importlib.metadata.EntryPoint]

Every installed vllm.general_plugins entry point belonging to this package.

self_check

self_check() -> None

Load the declared vLLM plugins the way vLLM does and assert the process-wide patches are applied.

Unlike vLLM's own plugin loader this does not swallow import errors. An unimportable plugin module is logged and skipped by vLLM, leaving a server that serves plaintext.

This check is intended for image build time.

Raises:

Type Description
RuntimeError

If no Stained Glass plugin entry points are installed.

RuntimeError

If a patch that does not depend on a built application failed to apply.