Skip to main content

Crate llm_inspect

Crate llm_inspect 

Source
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:

  1. Is this input safe to send? — Inspector::scan looks 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::redact masks what it found.
  2. Is this output safe to act on? — OutputValidator::validate checks 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§

AllowList
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.
OutputPolicy
What an output must satisfy.
OutputReport
Result of OutputValidator::validate.
OutputValidator
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 Inspector or an OutputValidator.
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.
ViolationKind
Kind of an output violation.

Constants§

DEFAULT_RULES_TOML
The bundled default rule set, as TOML.

Functions§

contains_html
Returns true if text contains something that looks like an HTML tag, comment or CDATA section.
is_invisible
Returns true for characters that are removed during normalization.
strip_html
Removes HTML tags, comments and CDATA markers from text.