
Run Crash-Resumable, Schema-Enforced Batch Extraction Over a Data Frame
Source:R/extract.R
airgap_extract.RdProcesses text rows in an R data frame through a local air-gapped LLM
runtime into a strictly typed tibble with:
Pre-flight air-gap isolation verification (
preflight_isolation_check()),Mandatory pre-inference PII redaction or keyed HMAC-SHA256 pseudonymization (or explicit
"verified_deidentified"attestation),Strict JSON schema validation (
validate_extraction()) with automatic structured repair retries (build_repair_prompt()),Crash-resumable atomic per-row JSONL checkpointing (never storing raw input text), and
Optional automatic hash-chained PII-free IRB/HIPAA audit logging (
audit_log_append()).
Usage
airgap_extract(
data,
text_col,
schema,
runtime,
prompt_template = NULL,
id_col = NULL,
pii_policy = c("redact", "pseudonymize", "verified_deidentified"),
pii_config = NULL,
pii_key = NULL,
vault = NULL,
vault_path = NULL,
encrypt_vault = TRUE,
reidentify_output = FALSE,
checkpoint_path = NULL,
resume = TRUE,
retry_failed = FALSE,
max_retries = 2L,
container_spec = NULL,
model_path = NULL,
allow_internal_network = FALSE,
strict_proxy = TRUE,
output_pii_action = c("redact", "error", "warn", "none"),
audit_log_path = NULL,
run_id = NULL,
progress = FALSE
)Arguments
- data
A data frame containing input text rows.
- text_col
Character scalar name of the text column in
data.- schema
An
extraction_schema()object defining output column types and constraints.- runtime
A local air-gapped runtime created by
runtime_ollama(),runtime_openai_local(), orruntime_mock().- prompt_template
Optional character scalar prompt template containing
"{text}". Defaults to a strict JSON schema extraction prompt.- id_col
Optional character scalar column name in
datasupplying unique non-NA row identifiers. IfNULL, synthesizes.row_idas"1","2", ...,"N".- pii_policy
Character scalar pre-inference privacy policy:
"redact"(default),"pseudonymize", or"verified_deidentified".- pii_config
Optional
pii_config()object used whenpii_policyis"redact"or"pseudonymize". Defaults topii_config().- pii_key
Secret key (e.g., from
pii_vault_key()) required whenpii_policy = "pseudonymize".- vault
Optional existing
airgap_pii_vaultto accumulate mappings whenpii_policy = "pseudonymize".- vault_path
Optional path to persist the separate encrypted PII vault when
pii_policy = "pseudonymize".- encrypt_vault
Logical scalar; encrypt saved vault file. Defaults to
TRUE.- reidentify_output
Logical scalar; if
TRUEandpii_policy = "pseudonymize", locally re-identifies character output columns using the vault after inference. Defaults toFALSE.- checkpoint_path
Optional path to an atomic JSONL checkpoint file enabling crash-resumable execution across interruptions.
- resume
Logical scalar; if
TRUE(default) andcheckpoint_pathexists, skips rows already committed in the checkpoint. IfFALSE, starts a fresh checkpoint file (overwriting any existing file atcheckpoint_path).- retry_failed
Logical scalar; when resuming from a checkpoint, whether to re-attempt rows previously recorded with
.status == "failed". Defaults toFALSE.- max_retries
Non-negative integer maximum structured repair retries after an initial invalid generation. Defaults to
2L.- container_spec
Optional
airgap_container_spec()verified in pre-flight and recorded in the run manifest/audit trail. Defaults toruntime$container_spec.- model_path
Optional path to local model weights verified against
container_spec$model_digestorruntime$model_digestduring pre-flight.- allow_internal_network
Logical scalar passed to
preflight_isolation_check(). Defaults toFALSE.- strict_proxy
Logical scalar passed to
preflight_isolation_check()controlling whether unbypassed outbound proxy env vars fail closed. Defaults toTRUE.- output_pii_action
Character scalar controlling post-inference PII leakage scanning of generated character schema fields (defending against prompt-injected or memorized PII echo):
"redact"(default, scrubs leaked PII before checkpointing/returning),"error"(aborts withairgap_output_pii_error),"warn", or"none". Automatically skipped whenpii_policy = "verified_deidentified"unless explicitly requested.- audit_log_path
Optional path to an immutable hash-chained JSONL audit log appended via
audit_log_append().- run_id
Optional character scalar run identifier. Defaults to an auto-generated UTC run ID.
- progress
Logical scalar; emit brief CLI progress summary. Defaults to
FALSE.
Value
A tibble of class c("airgap_extraction", "tbl_df", "tbl", "data.frame") containing the row ID column, strictly typed schema
columns, and per-row metadata (.status, .attempts, .error,
.elapsed_ms). Attachable provenance objects are accessed via
extraction_manifest(), extraction_privacy_report(),
extraction_preflight(), extraction_vault(), and
extraction_throughput().
Examples
df <- tibble::tibble(
note_id = c("N1", "N2"),
note_text = c(
"Dr. Jane Doe (MRN: 102938) reports mild anxiety, sleep improved.",
"Email bob@example.org for scheduling; mood stable."
)
)
sc <- extraction_schema(
severity = schema_field("enum", values = c("mild", "moderate", "severe")),
score = schema_field("integer", min = 0L, max = 10L)
)
res <- airgap_extract(df, "note_text", sc, runtime_mock(), id_col = "note_id")
res
#> # A tibble: 2 × 7
#> note_id severity score .status .attempts .error .elapsed_ms
#> <chr> <chr> <int> <chr> <int> <chr> <dbl>
#> 1 N1 severe 10 ok 1 NA 2
#> 2 N2 mild 2 ok 1 NA 1