Anonymizer icon indicating copy to clipboard operation
Anonymizer copied to clipboard

feat(interface): accept in-memory text records

Open afourniernv opened this issue 2 months ago • 1 comments

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) and TextRecordsInput input shapes.
  • Let the Python API accept TextRecordsInput alongside the existing file-backed AnonymizerInput without changing AnonymizerInput.source or 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_dataframe state: not an appropriate public correlation contract.

Compatibility

Existing AnonymizerInput(source=...) calls, generated schemas, and CLI behavior remain unchanged. The new shape is additive.

afourniernv avatar Sep 21 '26 18:09 afourniernv

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() and preview() preserve the input order of surviving records and include an id column in the public result dataframe. A dropped record appears in failed_records with 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 in failed_records. CSV IDs such as 001 should 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 through result.id_column, so callers can locate it without reading trace_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 its result.id_column metadata.

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.

lipikaramaswamy avatar Oct 06 '26 14:10 lipikaramaswamy