% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/workflow__audit.R
\name{asa_audit}
\alias{asa_audit}
\title{Audit Enumeration Results for Completeness and Quality}
\usage{
asa_audit(
  result,
  query = NULL,
  known_universe = NULL,
  checks = c("completeness", "consistency", "gaps", "anomalies"),
  backend = c("claude_code", "langgraph"),
  claude_model = "claude-sonnet-4-20250514",
  llm_model = "gpt-4.1-mini",
  interactive = FALSE,
  confidence_threshold = 0.8,
  timeout = 120,
  verbose = TRUE,
  agent = NULL
)
}
\arguments{
\item{result}{An \code{asa_enumerate_result} object or a data.frame to audit}

\item{query}{The original enumeration query (inferred from result if NULL)}

\item{known_universe}{Optional vector of expected items for completeness check}

\item{checks}{Character vector of checks to perform. Options: "completeness",
"consistency", "gaps", "anomalies". Default runs all checks.}

\item{backend}{Backend to use for auditing: "claude_code" (CLI) or "langgraph"}

\item{claude_model}{Model to use with Claude Code backend}

\item{llm_model}{Model to use with LangGraph backend}

\item{interactive}{If TRUE and using claude_code backend, spawn an interactive
Claude Code session instead of programmatic invocation}

\item{confidence_threshold}{Flag items with confidence below this threshold}

\item{timeout}{Timeout in seconds for the audit operation}

\item{verbose}{Print progress messages}

\item{agent}{Existing asa_agent for LangGraph backend (optional)}
}
\value{
An \code{asa_audit_result} object containing:
  \item{data}{Original data with audit columns added (_audit_flag, _audit_notes)}
  \item{audit_summary}{High-level summary of findings}
  \item{issues}{List of identified issues with severity and descriptions}
  \item{recommendations}{Suggested remediation queries}
  \item{completeness_score}{0-1 score for data completeness}
  \item{consistency_score}{0-1 score for data consistency}
}
\description{
Validates enumeration results for completeness, consistency, and data quality
using either Claude Code (CLI) or a LangGraph-based audit pipeline.
}
\details{
The audit function adds three columns to the data:
\itemize{
  \item \code{_audit_flag}: "ok", "warning", or "suspect"
  \item \code{_audit_notes}: Explanation of any issues
  \item \code{_confidence_adjusted}: Revised confidence after audit
}

## Audit Checks

\strong{completeness}: Checks for missing items by comparing against
  known_universe (if provided) or using domain knowledge.

\strong{consistency}: Validates data types, patterns, and value ranges.

\strong{gaps}: Identifies systematic patterns of missing data
  (geographic, temporal, categorical gaps).

\strong{anomalies}: Detects duplicates, outliers, and suspicious patterns.
}
\examples{
\dontrun{
# Audit enumeration results with Claude Code
senators <- asa_enumerate(
  query = "Find all current US senators",
  schema = c(name = "character", state = "character", party = "character")
)
audit <- asa_audit(senators, backend = "claude_code")
print(audit)

# Audit with known universe for precise completeness check
audit <- asa_audit(senators, known_universe = state.abb)

# Interactive mode for complex audits
asa_audit(senators, backend = "claude_code", interactive = TRUE)

# Use LangGraph backend
audit <- asa_audit(senators, backend = "langgraph", agent = agent)
}

}
