R/AI_applyAnonymization.R
AI_applyAnonymization.RdUses an agentic loop to explore multiple anonymization strategies. The LLM proposes strategies as structured tool calls, each is evaluated with a combined utility score, and the best is selected.
An object of class sdcMicroObj.
Desired k-anonymity level (default 3).
If TRUE, prints progress and scores for each strategy.
LLM model identifier. If NULL, a default is chosen per provider.
API key. If NULL, auto-detected from environment variables.
LLM provider: "openai" (default), "anthropic", or
"custom" for any OpenAI-compatible endpoint.
Base URL for the API endpoint. Required when provider = "custom".
Logical; if TRUE (default) and session is interactive, shows the
best strategy and asks for confirmation before applying.
Number of refinement iterations after the initial batch (default 2).
Number of strategies in the initial batch (default 3).
Numeric vector of length 3: weights for suppression rate,
category loss, and IL1 in the utility score. Default c(1/3, 1/3, 1/3).
If TRUE, generates internal and external reports.
Modified sdcMicroObj with the best anonymization strategy applied.
if (FALSE) { # \dontrun{
if (interactive() && nzchar(Sys.getenv("OPENAI_API_KEY"))) {
library(sdcMicro)
data(testdata)
sdc <- AI_createSdcObj(dat = testdata, policy = "open", confirm = FALSE)
sdc <- AI_applyAnonymization(sdcObj = sdc, k = 3, verbose = TRUE, confirm = FALSE)
}
} # }