Skip to contents

Persists a shieldr_audit object as JSON Lines, CSV, or RDS for operational auditability across LLM workflows.

Usage

write_audit_log(
  audit,
  path,
  format = "jsonl",
  include_content = FALSE,
  show_stats = FALSE
)

Arguments

audit

A shieldr_audit object.

path

Output file path.

format

One of "jsonl", "csv", or "rds".

include_content

Whether to write raw text and finding excerpts from a full-content audit. Defaults to FALSE.

show_stats

Show file-writing time, token estimate, and network status as messages.

Value

The path, invisibly.

Details

JSON Lines is the preferred append-only format for production logs because each call writes one complete audit object as one line. CSV flattens findings into one row per finding, which is convenient for spreadsheets and simple dashboards but loses some nested structure. The CSV path preserves common metadata such as context row index, context source, tool name, conversation role, and reviewer error counts. RDS preserves the R object exactly and overwrites the target path.

By default, content is stripped again before writing, including when an older or explicitly full-content audit object is supplied. To persist raw content, the caller must set include_content = TRUE explicitly and protect the destination path.

Examples

audit <- shieldr_audit(NULL, NULL, NULL, "hello", NULL, 0, 1L, "allow")
path <- tempfile(fileext = ".jsonl")
write_audit_log(audit, path)