Skip to content
Back

How Rota Nacional isolates person names in Rust and ONNX without storing text

See the two-stage architecture behind Rota Nacional's rn-privacy-0.3.0 barrier in São Paulo: Brazilian rules, quantized models in Rust, UTF-16 offsets, limits and real metrics.

Rota Nacional · Published · Reviewed

Why plain regex falls short and another LLM costs too much

Regular expressions detect CPF, CNPJ, email addresses and phone numbers reliably when patterns are structured, yet miss person names in natural sentences, clinical notes or customer support messages. Sending raw text to a second generative LLM only to redact PII increases latency, raises request cost and sends sensitive inputs outside your boundary again.

In Rota Nacional, the privacy barrier handles this step before the response model or directly through /v1/privacy/clean. Deterministic rules verify check digits for CPF, numeric and alphanumeric CNPJ, and Brazilian health cards (CNS), while a dedicated neural engine in São Paulo locates person names in context.

Position-only isolation in Rust and ephemeral streaming restoration

  • Strict position-only contract: the isolated AWS Lambda function (provided.al2023, x86_64) runs the rn-privacy-0.3.0 Rust binary with dynamic ONNX Runtime 1.24.4 and two SHA-256-pinned models (MiniLM Q4 and multilingual DistilBERT INT8).
  • UTF-16 offsets only: each internal call is bounded to up to 16 texts and 8,192 UTF-8 bytes, with Unicode UAX #15 and #29 alignment so decomposed accents and emojis never shift offsets. The response returns only start, end, label and score.
  • In-memory restoration: under the placeholder policy, the gateway swaps names and documents for markers ([PESSOA_1], [CPF_1]), restores original values in full JSON or SSE streaming responses and discards the map once the request finishes.
  • Fail-closed protection: when person detection is required and unavailable, the request returns HTTP 503 and nothing is forwarded to a model provider; requests above 256 KB return 413.

Measured São Paulo runtime numbers and explicit limits

Migrating from Node.js 22 to Rust on provided.al2023 with the exact same neural weights and v1 JSON contract reduced the deployment package from 126.7 MB to 106.9 MB compressed and allowed shrinking Lambda memory from 2,048 MB to 1,024 MB. In live AWS measurements in São Paulo, cold initialization dropped from around 6 s to 3.57 s, typical warm batch calls ran in 70 ms to 103 ms and worst-case 8 KB peak memory reached 589 MB.

Across five synthetic evaluation suites totaling 184 inputs, the engine matched 184 of 184 character intervals from version 0.2.0: 97.77% character recall and 96.69% precision on the 16 original texts (13/13 complete names), plus 99.77% recall and 95.14% precision on the 30 additional texts (21/22 complete names). These corpora are synthetic regression sets and do not guarantee universal detection on arbitrary text.

How to evaluate and integrate today

You can test deterministic Brazilian patterns right away in the public sandbox without an account, or sign in with verified email for a 7-day free trial (up to 100,000 tokens on the Fast model, no card required) to evaluate full text sanitization with the name engine. Organizations choose placeholder, redact, block (HTTP 422) or monitor.

For automated workflows and agents, call POST /v1/privacy/clean without invoking a generative model, or send protected chat through the rota/* catalog on OpenAI-compatible (/v1/chat/completions) and Anthropic-compatible (/v1/messages) routes using prepaid Pix credit in BRL or x402 per-call settlement where supported.

Frequently asked questions

Does the name engine store input text or keep a restoration table?

No. The detector receives only bounded text slices, returns UTF-16 offsets alone and retains no state across requests. The replacement map lives solely in gateway request memory.

Can I run the privacy barrier without calling a generative AI model?

Yes. POST /v1/privacy/clean runs Brazilian rules and Rust neural name detection and returns sanitized text or HTTP 422 under block policy without forwarding content to any generative model.

Keep reading

Looking for something else?DocumentationContact