Skip to contents

scan_conversation() scans multi-message chat histories instead of a single string. Each message is scanned with the role-appropriate surface and the returned reports preserve message index and role in metadata.

Usage

scan_conversation(
  messages,
  role_col = "role",
  content_col = NULL,
  policy = "enterprise_default",
  reviewer = NULL,
  checks = "rules",
  redaction = NULL,
  scanners = scanner_options(),
  show_tokens = FALSE
)

Arguments

messages

A data frame with role and content columns, a list of message objects with role and content fields, or a character vector of user messages.

role_col

Role column name for data-frame inputs.

content_col

Content column name for data-frame inputs. If NULL, a likely column such as content, text, or message is inferred.

policy

A shieldr_policy or built-in policy name.

reviewer

Optional reviewer function or object with $chat().

checks

One of "rules", "nlp", "llm", or "both".

redaction

Optional redaction strategy from redaction_strategy().

scanners

Optional scanner configuration from scanner_options().

show_tokens

Whether to attach token counts when ellmer is available.

Value

A list of shieldr_report objects, one per message.

Details

Role handling:

This function does not assemble or call a model. It is intended for preflight checks, audits, and regression tests over stored chat histories.

Examples

history <- data.frame(
  role = c("user", "assistant"),
  content = c("Summarize this.", "I will now delete the records."),
  stringsAsFactors = FALSE
)

scan_conversation(history)
#> [[1]]
#> llmshieldr report
#> action: allow
#> risk_score: 0.000
#> findings: 0
#> 
#> [[2]]
#> llmshieldr report
#> action: block
#> risk_score: 1.000
#> findings: 1
#>