API reference¶
Auto-generated from the source docstrings. The public surface is small: a unified adapter layer for targets, and a probes layer for attack cases, detectors and scans.
Adapters¶
The provider-agnostic target layer. get_adapter builds an adapter; vendor SDKs import lazily.
llmsectest.adapters ¶
Unified LLM adapter layer.
Use :func:get_adapter to obtain a provider-agnostic :class:LLMAdapter.
Vendor SDKs are imported lazily, so only the providers you actually use need to
be installed.
LLMAdapter ¶
Bases: ABC
Provider-agnostic chat-completion interface.
Concrete adapters lazily import their vendor SDK inside __init__ so that
importing this package never requires every provider's dependency to be
installed.
Source code in src/llmsectest/adapters/base.py
complete
abstractmethod
¶
prompt ¶
Convenience: send a single user turn, return the response text.
Source code in src/llmsectest/adapters/base.py
CompletionRequest
dataclass
¶
CompletionRequest(
messages: list[Message],
max_tokens: int = 512,
temperature: float = 0.0,
stop: list[str] | None = None,
extra: dict = dict(),
)
CompletionResponse
dataclass
¶
CompletionResponse(
text: str,
model: str,
provider: str,
raw: object = None,
usage: dict = dict(),
)
Role ¶
Bases: str, Enum
get_adapter ¶
Construct an adapter for provider (e.g. "openai", "mock").
Source code in src/llmsectest/adapters/__init__.py
available_providers ¶
register_adapter ¶
Register a custom adapter. target is a class or "module:Class".
Application endpoint target¶
llmsectest.adapters.app_endpoint ¶
Target a real LLM application by its HTTP endpoint.
This is the faithful way to security-test an application (vs. a bare model): we
POST the attacker's input to the application's own chat endpoint and read its
reply, so the app's real system prompt, guardrails, RAG and tools are all in the
loop. We send only the attacker turn — the application supplies its own
system prompt — so any provided system message is intentionally ignored.
Zero extra dependencies (stdlib urllib). Request/response shapes vary per
app, so both are configurable; the response field is auto-detected across common
shapes (reply/response/message/content or OpenAI-style
choices[0].message.content) when not given explicitly.
AppEndpointAdapter ¶
AppEndpointAdapter(
endpoint: str,
model: str | None = None,
request_field: str = "message",
response_path: str | None = None,
headers: dict[str, str] | None = None,
extra_body: dict[str, object] | None = None,
timeout: float = 120.0,
)
Bases: LLMAdapter
Drive a running LLM application via its HTTP chat endpoint.
Source code in src/llmsectest/adapters/app_endpoint.py
Probes¶
Attack cases, target resolution, the runner, and application-mode scans.
llmsectest.probes ¶
Adapter-driven OWASP security probes.
A probe sends an attacker prompt through the unified :class:LLMAdapter and a
detector scores the reply. The corpus currently covers OWASP LLM01 (prompt
injection), LLM02 (sensitive information disclosure), LLM05 (improper output
handling), LLM06 (excessive agency) and LLM07 (system prompt leakage); the
packaged pytest suite in :mod:llmsectest.suite runs them.
ProbeCase
dataclass
¶
ProbeCase(
id: str,
owasp: str,
title: str,
severity: str,
technique: str,
user_prompt: str,
system_prompt: str,
detector: str,
forbidden: tuple[str, ...],
)
One OWASP attack case driven through the unified LLM adapter.
ProbeOutcome
dataclass
¶
The result of running one :class:ProbeCase against a target adapter.
resolve_target ¶
Resolve a target spec into an adapter.
Accepts the demo keywords demo/demo-vulnerable/demo-defended;
app:<url> to test a running application by its HTTP endpoint (the
faithful black-box target — the app supplies its own system prompt); a bare
provider (mock); or provider:model (e.g. openai:gpt-4o-mini,
ollama:gemma4:e2b-it-q4_K_M for a local model). Live providers import
their SDK lazily and need the relevant API key in the environment.
Source code in src/llmsectest/probes/demo.py
run_probe ¶
Send case to adapter and apply its detector to the reply.
Source code in src/llmsectest/probes/runner.py
app_cases ¶
Build OWASP attack cases against a real application's own system_prompt.
Source code in src/llmsectest/probes/application.py
run_app_scan ¶
Run the application-mode OWASP cases for app_name against target.
target is an :class:~llmsectest.adapters.base.LLMAdapter driving the
model the application uses (e.g. a local Ollama model — no paid calls). Each
case wears the application's real system_prompt, so we are testing the
application's guardrails, not the bare model.