% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/rules.R
\name{shieldr_rule}
\alias{shieldr_rule}
\title{Construct a \code{shieldr_rule}}
\usage{
shieldr_rule(
  id,
  pattern = NULL,
  fn = NULL,
  owasp = NULL,
  severity = "medium",
  action = "redact",
  description = ""
)
}
\arguments{
\item{id}{A unique rule identifier.}

\item{pattern}{A regular expression pattern, or \code{NULL}.}

\item{fn}{A predicate function, or \code{NULL}.}

\item{owasp}{Optional OWASP LLM category such as \code{"llm01"}.}

\item{severity}{One of \code{"low"}, \code{"medium"}, \code{"high"}, or \code{"critical"}.}

\item{action}{One of \code{"allow"}, \code{"redact"}, or \code{"block"}.}

\item{description}{Human-readable rule description.}
}
\value{
A \code{shieldr_rule} S3 object.
}
\description{
Creates a validated rule for the llmshieldr rule engine. Rules map to OWASP
LLM Top 10 categories where possible; see \url{https://genai.owasp.org/llm-top-10/}.
}
\details{
A rule is the atomic unit of a policy. Each rule either supplies a regular
expression pattern or an R function. Regex rules are applied with
\code{gregexpr(..., perl = TRUE)} and can produce character spans for redaction.
Function rules receive the full text and can return \code{TRUE}, \code{FALSE}, a
finding list, a list of finding lists, or a data frame of findings.

\code{severity} is converted to a numeric score by the scanner:
\itemize{
\item \code{low}: \code{0.1}
\item \code{medium}: \code{0.3}
\item \code{high}: \code{0.6}
\item \code{critical}: \code{1.0}
}

The scanner caps the summed report score at \code{1.0}. Critical findings and
rules with \code{action = "block"} force the resolved report action to \code{block}.
}
\examples{
shieldr_rule(
  id = "demo.email",
  pattern = "\\\\\\\\b[^@]+@example\\\\\\\\.com\\\\\\\\b",
  owasp = "llm02",
  description = "Example-domain email address"
)
}
