Skip to content

Laranon Adds Reversible PII Masking for Laravel Apps Calling LLMs

Laranon, a new Laravel package by Eduardo Lázaro, replaces names, ID numbers and bank details with placeholder tokens before text reaches an LLM, then restores them in the reply. It requires PHP 8.2+ and Laravel 12+.

3 min readBased on 1 source0 views
AI & ML

TL;DR

  • Laranon swaps personal data for placeholder tokens before a prompt goes to an LLM, and keeps the token map on your server.
  • The package ships detection packs for Spanish and English and checks IBANs, card numbers and several Spanish ID formats.
  • Three replacement strategies cover LLM requests, documents that must read normally, and logs.

What the package does

Laranon is a Laravel package by Eduardo Lázaro that removes personal data from text before the text goes to a large language model. It replaces names, ID numbers and bank details with placeholder tokens such as «PER_1» or «DNI_1». The map from each token to its real value stays on your server. When the model replies, the map is used to put the real values back. The package has no dependencies beyond Laravel itself.

The example in the package documentation shows the flow. A message mentioning a client's name, a US Social Security number and a UK-style IBAN is anonymized, sent to the model, and the reply is passed to a restore call. The model only ever sees the tokens.

Detection and validation

Detection is based on pattern matching with checks that reduce false positives. Laranon validates IBANs, credit card numbers and several Spanish formats (DNI, NIE, CIF, NSS and CCC) using checksums. A DNI with a wrong control letter is ignored. Postal codes, five-digit ZIP codes and passport numbers are matched only when nearby words identify them.

Name handling works word by word. Laranon gives each word in a name its own token and does not try to match names to a real person, so "Smith" receives the same token in "John Smith" and "Mr. Smith". Single common words such as "Luz" are replaced only when a surname or title sits next to them. The English name list is built from US Social Security baby name data and the 2010 US Census surname list. Before production use, the package's laranon:scan command lists every value it would replace in a sample file, with type, offset and confidence score.

Sessions, scopes and streaming

A single chat turn may include the user's message, retrieved documents and tool results, and all of them must use the same tokens. For this, the README recommends an Anonymizer session, which keeps its map in memory only and discards it when the request ends. Chat history kept with real values in a database can be anonymized again on each turn, and Laranon assigns tokens in the order values appear, so each value keeps its token.

For work that spans several requests, such as a queued job, Laranon uses named scopes. By default the map is stored in the cache for six hours, and it can instead be kept in the database or in a per-request array. Cache and database maps are encrypted with the application key. Calling forget() deletes the map, after which the tokens in data already sent cannot be restored. Laranon also handles streaming responses: a token split across two server-sent event chunks is still restored.

Replacement strategies and logs

Laranon offers three strategies. The default token strategy writes placeholders that can be restored, and the package recommends it for LLM requests. The faker strategy writes fake values in the same format, for example a valid-looking DNI, and these can also be restored, which suits documents that must look normal. The redact strategy writes labels such as [DNI] and keeps no map, so values cannot be recovered. The package uses redact for its log tap and for the HTTP macro that scrubs outgoing request bodies.

Why it matters

Teams that send customer text to a hosted model often need to keep personal data out of the provider's hands. Laranon offers one way to do that inside a Laravel application, with the token map kept on the team's own servers. It also brings the same masking to logs and outgoing HTTP calls. The package requires PHP 8.2 or later and Laravel 12 or later, and it is installed with Composer. Before relying on it, teams should run the scan command against their own data, since the README itself recommends this and detection quality depends on the data. The source code and documentation are in the project's GitHub repository.

Sources

This article was written by Blozhik from the reporting below. Read the originals for full detail.

LaLaranon: Reversible PII Anonymization for Laravel and LLMsLaravel News
Was this useful?

Keep reading

Discussion · 0

Sign in to join the discussion. Liking does not need an account.Sign inRegister
Loading comments…
blozhikDeveloper news from across the web, explained. Every story links to its original sources.