Privacy Filter is a Laravel package that detects private entities — names, emails, and other personally identifiable information — in arbitrary text. It wraps the privacy-filter.cpp command-line binary, a GGML inference engine for OpenAI's privacy-filter token-classification models, and exposes the results through a PHP API.
Classifying Text into Entities
The main entry point is the
entities()
method, which runs the model over a string and returns
Entity
instances. Each entity carries its type, the matched text, the start and end byte offsets, and a confidence score:
使用
DirectoryTree\PrivacyFilter\Facades\PrivacyFilter
;$entities
=
PrivacyFilter
::
entities
(
'Contact John Doe at jdoe@example.com.'
(英文):foreach
($entities
作为
$entity) {
回声
实体
->
type;
// private_email
回声
实体
->
文本;
// jdoe@example.com}
Because the offsets are exact UTF-8 byte positions, you can map each detected entity back to its location in the original text rather than relying on string matching alone.
Confidence Thresholds
Classifications default to a 0.5 confidence threshold. You can raise or lower it per call to trade recall for precision — a higher threshold returns fewer, more certain entities:
$entities
=
PrivacyFilter
::
entities
(
文本
:
'Contact John Doe at jdoe@example.com.'
,
临界点
:
0.75
,(英文):
Redacting Detected Text
The package detects entities; what you do with them is up to you. A redaction pass is a reduce over the returned entities:
已编辑
=
收集
($entities)
->
减少
(
功能
(
细绳
$text, $entity) {
返回
str_replace
($entity
->
text,
'[redacted]'
, $text);}, $text);
Faking Classifications in Tests
Running the binary and loading the model in a test suite is slow, so Privacy Filter ships a
fake()
method that returns predetermined entities without invoking the binary:
使用
DirectoryTree\PrivacyFilter\Entity
;使用
DirectoryTree\PrivacyFilter\Facades\PrivacyFilter
;PrivacyFilter
::
伪造的
([
新的
Entity
(
类型
:
'private_email'
,
开始
:
20
,
结尾
:
36
,
分数
:
0.98
),]);
Your code under test then receives those entities as if the model had produced them.
安装和设置
Install the package with Composer, then run the installer to fetch the compiled binary for your operating system and download the required GGUF model:
作曲家
要求
directorytree/privacy-filterphp
工匠
privacy-filter:install
Prebuilt binaries for Linux, macOS (including ARM64), and Windows are distributed through
PrivacyFilterBinaries
. Pass
--force
to overwrite existing files. To customize the binary path, model path, process timeout, model URL, or release source, publish the configuration file:
php
工匠
供应商:发布
--tag=privacy-filter-config
Every classification loads the model into memory, so the package recommends running classifications on dedicated queue workers in production to keep memory usage predictable.
You can find the source and documentation on GitHub 。






