Skip to main content

Module llm

Module llm 

Source
Expand description

LLM prompt formatting — template resolution and prompt assembly.

Provides the built-in prompt templates and the helpers needed to build a structured LLM prompt from sanitized content and an optional sanitization report.

§Built-in templates

NameUse case
"troubleshoot"Incident triage — root cause, event sequence, remediation
"review-config"Config review — misconfigurations, security concerns, best practices
"review-security"Security posture — auth, exposure, TLS, CVEs, hardcoded secrets

A filesystem path can be supplied instead of a name; the file’s raw content is used as-is (no substitution is applied to custom templates).

§Prompt modes

Inline (format_llm_prompt) — sanitized bytes are embedded directly in <content> blocks. Use when piping output to an LLM without writing files.

Reference (format_llm_prompt_reference) — sanitized files are written to disk and the prompt lists their absolute paths. Use with --output so an agentic LLM can read the files via its own tools.

§Example

use sanitize_engine::llm::{format_llm_prompt, LlmEntry};

let entries: Vec<LlmEntry> = vec![
    ("app.log".to_string(), b"INFO start\nERROR disk full\n".to_vec()),
];
let prompt = format_llm_prompt("troubleshoot", &entries, None).unwrap();
assert!(prompt.contains("Root cause"));
assert!(prompt.contains("<content name=\"app.log\">"));

Constants§

PROMPT_PREAMBLE
Preamble injected into every built-in template, explaining the sanitization model to the LLM so it does not attempt to recover original values.
TEMPLATE_REVIEW_CONFIG
Built-in template for configuration review.
TEMPLATE_REVIEW_SECURITY
Built-in template for security posture review.
TEMPLATE_TROUBLESHOOT
Built-in template for incident troubleshooting.

Functions§

format_llm_prompt
Build a complete LLM prompt from a template, content entries, and an optional sanitization report.
format_llm_prompt_reference
Build a reference-mode LLM prompt: sanitized files are written to disk and the prompt lists their absolute paths for an agentic LLM to read directly.
resolve_llm_template
Resolve a template name or path to its instruction text.

Type Aliases§

LlmEntry
A single content entry for the LLM prompt: (label, sanitized_bytes).
LlmPathEntry
A reference entry for the LLM prompt: (input_label, sanitized_output_path).