-
Notifications
You must be signed in to change notification settings - Fork 0
primitives smart replacement map
Active contributors: Douwe de Vries
Smart replacement map is the core primitive that stores accepted Local AI replacements for selected columns. It validates model output, reuses replacements for repeated source values, records rejection reasons, and lets preview replacements carry into final output when they cover selected values.
| Path | Role |
|---|---|
crates/csv-anonymizer-core/src/smart.rs |
Defines Smart replacement requests, provider trait, replacement map, validation, batching, missing-value checks, and CSV or row collection. |
src-tauri/src/local_ai/provider.rs |
Implements SmartReplacementProvider for Ollama and converts provider requests into prompt calls. |
-
SmartReplacementProvideris a core trait withgenerate_replacements. -
SmartReplacementRequestincludes a column and a batch of source values. -
SmartReplacementis a provider-returned original and replacement pair. -
SmartReplacementEntryis the serializable DTO shared with the frontend. -
SmartReplacementMapstores replacements by column index and normalized source value. -
SmartReplacementRejectionReasonrecords invalid outputs such as unexpected source, missing output, empty output, same-as-original, contains-original, control character, duplicate source, and duplicate output. -
SMART_REPLACEMENT_VALUE_CAP_PER_COLUMNlimits collected unique values per selected Smart column.
sequenceDiagram
participant Rows as Rows or CSV
participant Smart as smart.rs
participant Provider as SmartReplacementProvider
participant Map as SmartReplacementMap
participant Strategy as TransformState
Rows->>Smart: collect unique selected Local AI values
Smart->>Map: reuse existing preview entries
Smart->>Provider: generate missing replacements in batches
Provider-->>Smart: original/replacement pairs
Smart->>Smart: validate replacements
Smart->>Map: insert accepted replacements and counts
Map-->>Strategy: replacement lookup during transform
Preview builds a replacement map from sampled rows and returns SmartReplacementEntry values to the frontend. Final CSV output receives those preview entries and checks whether they cover all selected Smart values. If values are missing, the backend needs a ready provider and requests only missing values. During transformation, TransformState looks up a replacement by column index and normalized original; a miss records a fallback and uses rule-based pseudonymization.
-
Transform strategy uses the map for the
localAistrategy and records fallback counts. - Privacy report includes accepted values, rejected candidates, rejection reasons, and fallback counts.
- Tauri command shell creates the provider for preview, paste, quick, and anonymize requests.
- Background jobs prepares Smart replacements before streaming full CSV output.
-
src-tauri/src/local_ai/provider.rssends prompts to Ollama through/api/generateand parses structured response JSON.
- Change provider trait shape, batching, value collection, value caps, or missing-value detection in
crates/csv-anonymizer-core/src/smart.rs. - Change validation rules or rejection reasons in
crates/csv-anonymizer-core/src/smart.rsand mirror DTO changes infrontend/src/types.ts. - Change Ollama request construction, response parsing, or provider enablement in
src-tauri/src/local_ai/provider.rs. - Change prompt schema or prompt text in
src-tauri/src/local_ai/prompt.rs. - Change Local AI status or model download behavior in Background jobs and related Local AI modules.
crates/csv-anonymizer-core/src/smart.rssrc-tauri/src/local_ai/provider.rssrc-tauri/src/local_ai/prompt.rs