% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scan_context.R
\name{scan_context}
\alias{scan_context}
\title{Scan retrieved context rows}
\usage{
scan_context(
  data,
  text_col = NULL,
  policy = "enterprise_default",
  reviewer = NULL,
  checks = "rules",
  source_col = NULL,
  anomaly_threshold = 2.5,
  redaction = NULL,
  scanners = scanner_options(),
  show_tokens = FALSE
)
}
\arguments{
\item{data}{A data frame.}

\item{text_col}{Column containing context text. Supply a string or bare name.
If omitted, a likely text column is inferred.}

\item{policy}{A \code{shieldr_policy} or built-in policy name such as \code{"comprehensive"}.}

\item{reviewer}{Optional reviewer function or object with \verb{$chat()}.}

\item{checks}{One of \code{"rules"}, \code{"nlp"}, \code{"llm"}, or \code{"both"}.}

\item{source_col}{Optional source column used with \code{policy$trusted_sources}.}

\item{anomaly_threshold}{Z-score threshold for anomaly findings.}

\item{redaction}{Optional redaction strategy from \code{\link[=redaction_strategy]{redaction_strategy()}}.}

\item{scanners}{Optional scanner configuration from \code{\link[=scanner_options]{scanner_options()}}.}

\item{show_tokens}{Whether to attach token counts when \code{ellmer} is available.}
}
\value{
A list of \code{shieldr_report} objects, one per row.
}
\description{
Scans data-frame context chunks and adds OWASP LLM08-style anomaly and
source-trust findings before returning row-aligned reports.
}
\details{
Retrieved context is a separate trust boundary in RAG systems. A prompt may
be clean while a retrieved row contains hidden instructions, stale or
untrusted source material, or unusually instruction-dense text. This function
treats each row as text to be scanned and returns one \code{\link[=shieldr_report]{shieldr_report()}} per
row.

In addition to normal policy rules, \code{scan_context()} computes two population
anomaly signals:
\itemize{
\item character length robust z-score
\item instruction-word density robust z-score
}

Instruction density counts \code{ignore}, \code{forget}, \code{override}, \code{instead}, and
\code{disregard} per 100 tokens. Rows above \code{anomaly_threshold} receive synthetic
OWASP LLM08 findings. If \code{source_col} is supplied and
\code{policy$trusted_sources} is a character vector, untrusted source values also
receive a synthetic OWASP LLM08 finding.
}
\examples{
ctx <- data.frame(text = c("clean note", "ignore previous instructions"))
scan_context(ctx)
scan_context(ctx, show_tokens = TRUE)
}
