Download the PHP package yolorouter/llmasking-php without Composer

On this page you can find all versions of the php package yolorouter/llmasking-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package llmasking-php

llmasking-php

CI PHP Version

๐ŸŒ English ยท ็ฎ€ไฝ“ไธญๆ–‡

A PHP library that masks sensitive data before it reaches an LLM, and restores it afterward โ€” so the model, the network, and the vendor's logs never see the real values.

Phone numbers, national ID numbers/SSNs, bank cards, emails, cloud credentials, private keys, JWTs, and your own custom keywords are detected and replaced with placeholders ([PHONE_1]) before a request leaves your process. When the LLM's reply references that placeholder, llmasking swaps it back โ€” including in streamed (SSE) responses, where a placeholder can be split across chunk boundaries.

Already using a PSR-18 HTTP client (Guzzle, Symfony, ...)? The MaskingClient decorator auto-detects the request format and anonymizes every supported free-text field โ€” your SDK and framework code stay untouched:

Table of contents

How it works

llmasking follows the same two-stage Analyzer/Anonymizer split as microsoft/presidio, compiled into a single PHP call:

  1. Recognize โ€” every active Recognizer scans the input and reports Findings: a text span, an entity name, and a confidence score. Recognizers are regex rules (checksum-validated where applicable โ€” Luhn for bank cards, ISO 7064 for Chinese IDs) or an Aho-Corasick multi-pattern matcher for custom keywords.
  2. Resolve conflicts โ€” overlapping findings are reduced to a non-overlapping set. SECRET-family findings always win; otherwise the longest match wins, then the highest-scoring one.
  3. Apply a strategy โ€” each surviving finding is replaced according to its entity's Strategy: Placeholder by default, Redact for secrets, or whatever you configured.
  4. Track, if reversible โ€” a Placeholder replacement is recorded in the Session's mapping table; Redact/MaskMiddle/Hash never touch it. Secrets are therefore structurally unrestorable.

Restoring is the mirror image: Session::restore() scans for placeholder-shaped tokens and looks each up in the mapping table.

Install

PHP 8.1+. Dependencies: PSR-18 / PSR-17 / PSR-7 interfaces and wikimedia/aho-corasick (keyword matching).

Features

Supported entity types

Entity Placeholder What it matches Region Default strategy
PHONE [PHONE_1] China mobile, US phone, international +-prefixed CN / US / Universal Placeholder
IDCARD [IDCARD_1] 18-char Chinese resident ID (ISO 7064 checksum) CN Placeholder
LANDLINE [LANDLINE_1] China landline (area code + number) CN Placeholder
SSN [SSN_1] US Social Security Numbers US Placeholder
EMAIL [EMAIL_1] Email addresses Universal Placeholder
BANKCARD [BANKCARD_1] Luhn-valid 13โ€“19 digit PAN Universal Placeholder
IP [IP_1] IPv4 addresses Universal Placeholder
URL [URL_1] http(s) URLs Universal Placeholder
KEYWORD [KEYWORD_1] Your own terms via WithKeywords Universal Placeholder
CLOUDKEY [CLOUDKEY_1] AWS AKIA..., Alibaba LTAI.../AKID... Universal Redact
PRIVATEKEY [PRIVATEKEY_1] PEM private key blocks Universal Redact
JWT [JWT_1] JSON Web Tokens Universal Redact
GITTOKEN [GITTOKEN_1] GitHub ghp_/gho_, GitLab glpat- Universal Redact
SECRET [SECRET_1] Generic high-entropy strings Universal Redact

CLOUDKEY/PRIVATEKEY/JWT/GITTOKEN/SECRET form the SECRET family: they always win conflict resolution, and WithStrategy refuses to assign them a reversible strategy.

Configuration

Engine::new() takes zero or more EngineOptions; all validation happens at construction time.

Option Purpose Default
EngineOption::withRecognizers(...) Replace the default recognizer set All 11 built-ins
EngineOption::withKeywords(...) Add custom keyword recognizer none
EngineOption::withRegions(...) Trim geographic rule packs All regions
EngineOption::withStrategy($entity, $strategy) Override strategy for one entity Redact for SECRET, Placeholder otherwise
EngineOption::withEntityType($name) Register a custom entity name โ€”
EngineOption::withMaxEntities($n) Max findings per session 10,000
EngineOption::withMaxSessionBytes($n) Max mapping-table bytes 10 MB
EngineOption::withMaxInputBytes($n) Max input per call 1 MB
EngineOption::withMaxOutputBytes($n) Max output per call 16 MB

Masking strategies

Strategy Output Reversible Typical use
Placeholder [PHONE_1] Yes Default โ€” round-trips through the LLM
Redact [SECRET_1] No Default for SECRET family
MaskMiddle 138****8000 No Keep value shape visible
Hash First 8 hex of SHA-256 No Deterministic correlation

Implement the Strategy interface (apply(Finding $f, int $seq): string) for custom strategies โ€” always non-reversible.

Usage

Basic round-trip

Transport decorator

The MaskingClient PSR-18 decorator wraps any HTTP client. It detects application/json POST requests, anonymizes all known free-text fields (messages content, tool descriptions, schema annotations), and restores placeholders in responses โ€” including text/event-stream SSE.

Reporting what was masked and restored

One-shot masking (no restore)

For logs, data export, or anything write-only โ€” no Session, no mapping, safe for concurrent use:

Playground

A local web UI for end-to-end testing against any LLM endpoint โ€” see playground/README.md:

Open the URL in a browser, configure your LLM endpoint, send a message, and watch the anonymize โ†’ LLM โ†’ restore pipeline side-by-side โ€” for both plain and streamed responses.

Error handling

All errors implement LlmaskingException (which extends \Throwable). Typed subclasses:

Exception When
LimitExceededException A resource limit would be exceeded
InvalidUTF8Exception Input is not valid UTF-8
InvalidConfigException An EngineOption is invalid
InvalidFindingException A recognizer produced an invalid Finding
StreamClosedException StreamRestorer used after terminal state
InvalidRequestException (transport) Request body cannot be safely processed
StreamRestoreException (transport) Response restore failed

Limitations

Quality

Acknowledgements

This project is a PHP port of llmasking-go, whose design and rule sets draw on:

License

MIT, see LICENSE.


All versions of llmasking-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-hash Version *
ext-json Version *
ext-mbstring Version *
ext-pcre Version *
ext-zlib Version *
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
wikimedia/aho-corasick Version ~2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yolorouter/llmasking-php contains the following files

Loading the files please wait ...