Expand description
Input and output security inspection for LLM applications.
llm-inspect sits between your application and a large language model and
answers two questions:
- Is this input safe to send? —
Inspector::scanlooks for personal data (PII), credentials (secrets) and prompt-injection patterns. Text is normalized first (NFKC, zero-width characters removed) so that full-width letters or hidden characters do not bypass the rules.Inspector::redactmasks what it found. - Is this output safe to act on? —
OutputValidator::validatechecks that a model response is JSON that matches a JSON Schema, that selected fields only contain allow-listed values, and that no HTML slipped in.
Rules are plain regular expressions declared in TOML, so they can be audited and extended without recompiling. The bundled rule set is a starting point, not a guarantee: pattern matching cannot detect every attack or every piece of personal data. Treat it as one layer in a defense-in-depth design, next to human approval, least privilege and audit logging.
§Example
use llm_inspect::{Decision, Inspector};
let inspector = Inspector::with_default_rules();
let report = inspector.scan("My AWS key is AKIAIOSFODNN7EXAMPLE, please deploy.");
assert_eq!(report.decision, Decision::Block);
assert_eq!(report.findings[0].rule_id, "secret.aws_access_key");
let redacted = inspector.redact("Contact me at taro@example.com");
assert_eq!(redacted.text, "Contact me at [REDACTED:PII]");Structs§
- Allow
List - An allow-list applied to the values selected by a JSON pointer.
- Finding
- One match of one rule.
- Inspector
- Scans input text against a
RuleSet. - Normalized
- Normalized text with a mapping back to byte offsets in the original.
- Output
Policy - What an output must satisfy.
- Output
Report - Result of
OutputValidator::validate. - Output
Validator - Validates model outputs against an
OutputPolicy. - Policy
- Decision thresholds and redaction settings.
- Redacted
- Result of
Inspector::redact. - Report
- Result of
Inspector::scan. - Rule
- A single detection rule.
- RuleSet
- A policy plus a list of rules; the unit that is loaded from TOML.
- Violation
- One problem found in an output.
Enums§
- Category
- What kind of problem a rule detects.
- Decision
- What the caller should do with the input.
- Error
- Errors returned while building an
Inspectoror anOutputValidator. - Severity
- How serious a finding is. Ordered from least to most severe.
- Validator
- Extra validation applied to a regex match before it becomes a finding.
- Violation
Kind - Kind of an output violation.
Constants§
- DEFAULT_
RULES_ TOML - The bundled default rule set, as TOML.
Functions§
- contains_
html - Returns
trueiftextcontains something that looks like an HTML tag, comment or CDATA section. - is_
invisible - Returns
truefor characters that are removed during normalization. - strip_
html - Removes HTML tags, comments and CDATA markers from
text.