Skip to navigation

Preview a Config

View as Markdown

This tutorial walks through the anonymizer.preview flow: defining a request, streaming a small anonymized sample, and inspecting the resulting frames.

For detection and replacement strategy details, see the open-source library documentation.

Prerequisites

Complete the tutorials prerequisites, which cover:

  • A running NeMo Helix cluster with the nemo anonymizer CLI available (see Setup).
  • An inference provider configured (default examples use nvidia-build).
  • A fileset named anonymizer-inputs with anonymizer-input.csv uploaded.

What preview Does

preview runs the Anonymizer pipeline on a small number of records and streams results back from the plugin service. The Python SDK collects the stream into a pandas DataFrame; the basic CLI streams NDJSON frames to stdout.

The plugin emits these frame kinds:

FramePurpose
logPipeline log lines forwarded from the library.
model_downloadFirst-run only: emitted while the PII detector model downloads (started/complete).
preview_datasetUser-facing anonymized records. The final dataset you usually care about.
trace_datasetInternal trace records used by display_record in notebooks.
failed_recordsPer-record failures with reasons. Emitted only when at least one record failed.
heartbeat, done, errorGeneric stream control frames.

Available preview surfaces:

SurfaceWhere it runsLocal pathsmodel_configs required
anonymizer.preview(...)Anonymizer plugin service (remote)RejectedRequired
nemo anonymizer previewAnonymizer plugin service (remote)RejectedRequired

Step 1: Build a PreviewRequest

A preview request bundles the AnonymizerConfig, the input spec, and model_configs / selected_models.

import os
from anonymizer.config.anonymizer_config import AnonymizerConfig
from anonymizer.config.replace_strategies import Redact
from data_designer.config import ModelConfig
from nemo_anonymizer_plugin.app.input import AnonymizerInputSpec
from nemo_anonymizer_plugin.app.task_config import PreviewRequest
from nemo_anonymizer_plugin.sdk.resources import AnonymizerResource
from nemo_helix_plugin.client.client import NemoClient
client = NemoClient.from_config()
anonymizer = AnonymizerResource(client)
WORKSPACE = client.resolve_workspace()
MODEL_PROVIDER = os.environ.get("NHX_ANON_PROVIDER", "nvidia-build")
config = AnonymizerConfig(
replace=Redact(format_template="[REDACTED_{label}]"),
)
model_configs = [
# The Anonymizer plugin manages a default PII entity detector, so it is not
# configured here (you may override it with a ModelConfig, but that is
# optional). These entries cover the remaining LLM roles.
ModelConfig(alias="gpt-oss-120b", provider=MODEL_PROVIDER, model="openai/gpt-oss-120b"),
ModelConfig(alias="nemotron-30b-thinking", provider=MODEL_PROVIDER, model="nvidia/nemotron-3.5-lightning-30b-a3b"),
]
request = PreviewRequest(
config=config,
data=AnonymizerInputSpec(
source=f"fileset://{WORKSPACE}/anonymizer-inputs#anonymizer-input.csv",
text_column="biography",
id_column="id",
),
model_configs=model_configs,
num_records=2,
)

Field reference:

FieldTypeNotes
configAnonymizerConfigThe library config. The example uses Redact; the plugin also supports substitute, annotate, hash, and rewrite.
data.sourcestringhttp(s) URL or fileset reference. See input source forms.
data.text_columnstringColumn containing text to anonymize. Defaults to text.
data.id_columnstringOptional record identifier column.
data.data_summarystringOptional short description passed to Anonymizer library prompts.
model_configslistRequired Data Designer ModelConfig entries. provider must reference an Inference Gateway provider name (or workspace/provider).
selected_modelsobjectOptional detection / replace / rewrite overrides on top of the bundled defaults. Requires model_configs.
num_recordsint (≥ 1)Number of records to preview. Defaults to 10.

Step 2: Run with the Python SDK

preview = anonymizer.preview(request)
preview.dataset # pandas DataFrame of anonymized records
preview.trace_dataset # detection trace
preview.failed_records # list[dict] of per-record failures (usually empty)
preview.display_record(0) # render record 0 with entity highlights in a notebook

AnonymizerResource.preview calls the plugin service: use a fileset or http(s) source, and include model_configs.

The CLI accepts the same request as a YAML or JSON spec file and streams NDJSON frames:

nemo anonymizer preview \
--spec-file /tmp/anonymizer-preview.yaml

AsyncAnonymizerResource.preview has the same signature and return type:

import asyncio
from nemo_anonymizer_plugin.sdk.resources import AsyncAnonymizerResource
from nemo_helix_plugin.client.client import AsyncNemoClient
async def run_preview():
async_client = AsyncNemoClient.from_config()
anonymizer = AsyncAnonymizerResource(async_client)
try:
return await anonymizer.preview(request)
finally:
await async_client.close()
preview = asyncio.run(run_preview())

Step 3: Persist Preview Records

AnonymizerPreviewResult.dataset and trace_dataset are pandas DataFrames, so save them with standard pandas methods:

preview.dataset.to_csv("anonymized-preview.csv", index=False)
preview.dataset.to_parquet("anonymized-preview.parquet", index=False)

AnonymizerPreviewResult stores everything in memory; nothing is persisted to disk by default. The dataset field is a regular pandas DataFrame and can be saved with to_csv or to_parquet.

Input Source Forms

The plugin accepts HTTP(S) URLs or Fileset references for data.source. Fileset references take any of the forms below; the workspace and fileset must already exist:

fileset://<workspace>/<fileset>#<path>
<workspace>/<fileset>#<path>
<fileset>#<path>

The #<path> fragment must resolve to a single .csv or .parquet file. The plugin downloads the file before constructing the Anonymizer library input and cleans up the temp directory when the preview completes.

Validate the Config Independently

If you want to validate just the AnonymizerConfig (and optionally a model_configs YAML) without running a preview, use nemo anonymizer validate:

from pathlib import Path
import yaml
Path("/tmp/anonymizer-config.yaml").write_text(yaml.safe_dump({
"replace": {"kind": "redact", "format_template": "[REDACTED_{label}]"},
}))
nemo anonymizer validate --config /tmp/anonymizer-config.yaml

validate checks the config against the model selection (for example, that a Substitute strategy has a replacement_generator model defined) and prints Config is valid. on success. It does not accept data.source, so input-source validation happens during preview or run.

Next Steps

  • Run a full job and inspect parquet output in the run tutorial.
  • Refer to SDK Resources for AnonymizerPreviewResult and AnonymizerResource.preview details.
  • Learn about rewrite and replacement strategy parameters in the library docs.