feat(interface): accept in-memory text records
Priority
Medium
Problem
Applications that already hold text in memory must write temporary CSV or Parquet files before calling Anonymizer. That adds avoidable I/O and complicates service integrations. Callers also need a stable way to correlate completed rows with their own request or event IDs, including when an input column name collides with a generated output column.
Proposed solution
- Add typed
TextRecord(id, text)andTextRecordsInputinput shapes. - Let the Python API accept
TextRecordsInputalongside the existing file-backedAnonymizerInputwithout changingAnonymizerInput.sourceor its JSON schema. - Preserve caller IDs and input order in the public result dataframe.
- Keep the CLI file-only; do not expose nested record objects as command-line flags.
- Retain existing file input behavior and validate configured ID columns.
Alternatives considered
- Temporary files: workable, but expensive and awkward for request-oriented services.
- Accepting a raw dataframe: broader and less explicit than the two fields the pipeline needs.
- Reading private
trace_dataframestate: not an appropriate public correlation contract.
Compatibility
Existing AnonymizerInput(source=...) calls, generated schemas, and CLI behavior remain unchanged. The new shape is additive.
I support adding TextRecord(id, text) and TextRecordsInput(records, data_summary) for Python callers. Can we define a correlation contract across in-memory and file-backed inputs?
- In-memory records: Each record has a non-empty, unique string ID.
run()andpreview()preserve the input order of surviving records and include anidcolumn in the public result dataframe. A dropped record appears infailed_recordswith that same caller ID. - File-backed input with
id_column: After loading the file, validate that the configured column exists and that its IDs are non-empty and unique. Normalize IDs to strings consistently so the value in the public dataframe matches the value used infailed_records. CSV IDs such as001should retain their textual form. - File-backed input without
id_column: Keep the existing generated internal record IDs and existing public dataframe behavior. - Column collisions: If the configured ID column has a name that collides with a generated output column, apply the existing input-column rename rule (for example,
final_entities→final_entities__input). Keep the resolved ID column in the public dataframe and expose its name throughresult.id_column, so callers can locate it without readingtrace_dataframe. - Pipeline failures: Use the configured caller ID for missing-record tracking at every stage. Successful rows retain their input order; failed rows are reported with their caller IDs.
- Evaluation:
Anonymizer.evaluate()should retain the ID column and itsresult.id_columnmetadata.
A missing, blank, or duplicate configured ID should raise an input error before model work begins. The same validation should apply to run() and preview().
This leaves AnonymizerInput.source required, keeps the CLI file-only, and gives applications a public way to correlate both successful and failed records.