Skip to main content

llm_inspect/
lib.rs

1//! Input and output security inspection for LLM applications.
2//!
3//! `llm-inspect` sits between your application and a large language model and
4//! answers two questions:
5//!
6//! 1. **Is this input safe to send?** — [`Inspector::scan`] looks for personal
7//!    data (PII), credentials (secrets) and prompt-injection patterns. Text is
8//!    normalized first (NFKC, zero-width characters removed) so that full-width
9//!    letters or hidden characters do not bypass the rules. [`Inspector::redact`]
10//!    masks what it found.
11//! 2. **Is this output safe to act on?** — [`OutputValidator::validate`] checks
12//!    that a model response is JSON that matches a JSON Schema, that selected
13//!    fields only contain allow-listed values, and that no HTML slipped in.
14//!
15//! Rules are plain regular expressions declared in TOML, so they can be audited
16//! and extended without recompiling. The bundled rule set is a starting point,
17//! not a guarantee: **pattern matching cannot detect every attack or every piece
18//! of personal data.** Treat it as one layer in a defense-in-depth design, next
19//! to human approval, least privilege and audit logging.
20//!
21//! # Example
22//!
23//! ```
24//! use llm_inspect::{Decision, Inspector};
25//!
26//! let inspector = Inspector::with_default_rules();
27//! let report = inspector.scan("My AWS key is AKIAIOSFODNN7EXAMPLE, please deploy.");
28//! assert_eq!(report.decision, Decision::Block);
29//! assert_eq!(report.findings[0].rule_id, "secret.aws_access_key");
30//!
31//! let redacted = inspector.redact("Contact me at taro@example.com");
32//! assert_eq!(redacted.text, "Contact me at [REDACTED:PII]");
33//! ```
34
35#![forbid(unsafe_code)]
36
37mod error;
38mod input;
39mod normalize;
40mod output;
41mod report;
42mod rules;
43
44pub use error::Error;
45pub use input::Inspector;
46pub use normalize::{Normalized, is_invisible};
47pub use output::{
48    AllowList, OutputPolicy, OutputReport, OutputValidator, Violation, ViolationKind,
49    contains_html, strip_html,
50};
51pub use report::{Decision, Finding, Redacted, Report};
52pub use rules::{Category, DEFAULT_RULES_TOML, Policy, Rule, RuleSet, Severity, Validator};