traceredact 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. traceredact-0.1.0/.gitignore +10 -0
  2. traceredact-0.1.0/LICENSE +166 -0
  3. traceredact-0.1.0/PKG-INFO +140 -0
  4. traceredact-0.1.0/README.md +118 -0
  5. traceredact-0.1.0/pyproject.toml +66 -0
  6. traceredact-0.1.0/src/traceredact/__init__.py +43 -0
  7. traceredact-0.1.0/src/traceredact/cli.py +172 -0
  8. traceredact-0.1.0/src/traceredact/detectors/__init__.py +17 -0
  9. traceredact-0.1.0/src/traceredact/detectors/base.py +109 -0
  10. traceredact-0.1.0/src/traceredact/detectors/pii.py +15 -0
  11. traceredact-0.1.0/src/traceredact/detectors/secrets.py +72 -0
  12. traceredact-0.1.0/src/traceredact/engine.py +362 -0
  13. traceredact-0.1.0/src/traceredact/integrations/__init__.py +5 -0
  14. traceredact-0.1.0/src/traceredact/integrations/anthropic.py +46 -0
  15. traceredact-0.1.0/src/traceredact/integrations/langchain.py +46 -0
  16. traceredact-0.1.0/src/traceredact/integrations/openai.py +60 -0
  17. traceredact-0.1.0/src/traceredact/policy.py +116 -0
  18. traceredact-0.1.0/src/traceredact/py.typed +0 -0
  19. traceredact-0.1.0/src/traceredact/rules.py +285 -0
  20. traceredact-0.1.0/tests/fixtures/agent_trace.json +33 -0
  21. traceredact-0.1.0/tests/fixtures/evasion_trace.json +25 -0
  22. traceredact-0.1.0/tests/fixtures/prompt.txt +12 -0
  23. traceredact-0.1.0/tests/test_cli.py +51 -0
  24. traceredact-0.1.0/tests/test_detectors.py +96 -0
  25. traceredact-0.1.0/tests/test_engine.py +180 -0
  26. traceredact-0.1.0/tests/test_evasion.py +92 -0
  27. traceredact-0.1.0/tests/test_fixtures.py +45 -0
  28. traceredact-0.1.0/tests/test_integrations.py +65 -0
  29. traceredact-0.1.0/tests/test_policy.py +42 -0
  30. traceredact-0.1.0/traceredact.yml +48 -0
@@ -0,0 +1,10 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .pytest_cache/
5
+ .mypy_cache/
6
+ .ruff_cache/
7
+ dist/
8
+ build/
9
+ *.egg-info/
10
+ uv.lock
@@ -0,0 +1,166 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the
49
+ original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work, excluding
103
+ those notices that do not pertain to any part of the Derivative
104
+ Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works.
111
+
112
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
113
+ any Contribution intentionally submitted for inclusion in the Work
114
+ by You to the Licensor shall be under the terms and conditions of
115
+ this License, without any additional terms or conditions.
116
+
117
+ 6. Trademarks. This License does not grant permission to use the trade
118
+ names, trademarks, service marks, or product names of the Licensor,
119
+ except as required for reasonable and customary use in describing the
120
+ origin of the Work and reproducing the content of the NOTICE file.
121
+
122
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed
123
+ to in writing, Licensor provides the Work (and each Contributor
124
+ provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
125
+ OR CONDITIONS OF ANY KIND, either express or implied, including,
126
+ without limitation, any warranties or conditions of TITLE,
127
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
128
+ PURPOSE. You are solely responsible for determining the
129
+ appropriateness of using or redistributing the Work and assume any
130
+ risks associated with Your exercise of permissions under this License.
131
+
132
+ 8. Limitation of Liability. In no event and under no legal theory,
133
+ whether in tort (including negligence), contract, or otherwise,
134
+ unless required by applicable law (such as deliberate and grossly
135
+ negligent acts) or agreed to in writing, shall any Contributor be
136
+ liable to You for damages, including any direct, indirect, special,
137
+ incidental, or consequential damages of any character arising as a
138
+ result of this License or out of the use or inability to use the
139
+ Work.
140
+
141
+ 9. Accepting Warranty or Additional Liability. While redistributing
142
+ the Work or Derivative Works thereof, You may choose to offer,
143
+ and charge a fee for, acceptance of support, warranty, indemnity,
144
+ or other liability obligations and/or rights consistent with this
145
+ License. However, in accepting such obligations, You may act only
146
+ on Your own behalf and on Your sole responsibility, not on behalf
147
+ of any other Contributor, and only if You agree to indemnify,
148
+ defend, and hold each Contributor harmless for any liability
149
+ incurred by, or claims asserted against, such Contributor by reason
150
+ of your accepting any such warranty or additional liability.
151
+
152
+ END OF TERMS AND CONDITIONS
153
+
154
+ Copyright 2026 traceredact contributors
155
+
156
+ Licensed under the Apache License, Version 2.0 (the "License");
157
+ you may not use this file except in compliance with the License.
158
+ You may obtain a copy of the License at
159
+
160
+ http://www.apache.org/licenses/LICENSE-2.0
161
+
162
+ Unless required by applicable law or agreed to in writing, software
163
+ distributed under the License is distributed on an "AS IS" BASIS,
164
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
165
+ See the License for the specific language governing permissions and
166
+ limitations under the License.
@@ -0,0 +1,140 @@
1
+ Metadata-Version: 2.4
2
+ Name: traceredact
3
+ Version: 0.1.0
4
+ Summary: Redact PII and secrets from AI prompts, traces and tool-call arguments before they reach your loggers.
5
+ Project-URL: Homepage, https://github.com/traceredact/traceredact
6
+ Project-URL: Issues, https://github.com/traceredact/traceredact/issues
7
+ Author: traceredact contributors
8
+ License: Apache-2.0
9
+ License-File: LICENSE
10
+ Keywords: dlp,llm,observability,pii,privacy,redaction,secrets
11
+ Requires-Python: >=3.11
12
+ Requires-Dist: pydantic>=2.6
13
+ Requires-Dist: pyyaml>=6.0
14
+ Requires-Dist: typer>=0.12
15
+ Provides-Extra: anthropic
16
+ Requires-Dist: anthropic>=0.25; extra == 'anthropic'
17
+ Provides-Extra: langchain
18
+ Requires-Dist: langchain-core>=0.2; extra == 'langchain'
19
+ Provides-Extra: openai
20
+ Requires-Dist: openai>=1.0; extra == 'openai'
21
+ Description-Content-Type: text/markdown
22
+
23
+ # traceredact
24
+
25
+ **Redact PII and secrets from AI prompts, agent traces and tool-call arguments
26
+ *before* they reach your loggers / observability backend.**
27
+
28
+ LLM apps log everything — prompts, agent traces, tool-call arguments — into
29
+ Langfuse / Helicone / Datadog / your own DB. Customer PII and API keys leak into
30
+ those traces. `traceredact` is a small, dependency-light library that detects
31
+ and redacts that data deterministically, in-process, before it leaves you.
32
+
33
+ It is **content-based**: it catches a `sk-…` key or a credit-card number even
34
+ when it sits under an innocuous JSON key — not just well-known field names.
35
+
36
+ > A missed secret is a real incident, so detection is treated as
37
+ > safety-critical: bounded (ReDoS-safe) patterns, entropy fallback, Luhn/IBAN
38
+ > validation, and adversarial evasion fixtures.
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pip install traceredact # or: uv add traceredact
44
+ ```
45
+
46
+ ## Usage (3 lines)
47
+
48
+ ```python
49
+ from traceredact import redact
50
+
51
+ result = redact({"args": {"email": "a@b.com", "key": "sk-1234567890abcdefABCDEFGH"}})
52
+ print(result.value) # {'args': {'email': '[REDACTED:pii]', 'key': '[REDACTED:secret]'}}
53
+ print(result.findings) # [Finding(detector_id='pii.email', json_path='args.email', ...), ...]
54
+ ```
55
+
56
+ `redact()` accepts a string, dict, list, or any nested mix. The input is never
57
+ mutated; `result.value` is a redacted copy and `result.findings` lists every hit
58
+ with its `detector_id`, `category`, `confidence`, `json_path` and `span`.
59
+
60
+ ### CLI (CI-gateable)
61
+
62
+ ```bash
63
+ traceredact scan ./logs/ # report findings as a table; exit 1 if any
64
+ traceredact scan trace.json -f json # machine-readable output for CI
65
+ traceredact redact trace.json -o redacted.json
66
+ ```
67
+
68
+ `scan` exits non-zero when anything is found, so you can gate a CI job on it.
69
+
70
+ ### SDK integrations
71
+
72
+ ```python
73
+ from openai import OpenAI
74
+ from traceredact.integrations.openai import wrap_openai
75
+
76
+ client = wrap_openai(OpenAI()) # prompts + completions now redacted in-flight
77
+ ```
78
+
79
+ Also: `traceredact.integrations.anthropic.wrap_anthropic(client)` and
80
+ `traceredact.integrations.langchain.RedactingCallbackHandler()`.
81
+
82
+ > **Limitation (MVP):** the wrappers patch the **synchronous, non-streaming**
83
+ > `create` call. Outbound prompts are always redacted, but **streamed**
84
+ > (`stream=True`) response *content* and **async** clients (`AsyncOpenAI`) are
85
+ > not yet redacted on the response side. Don't rely on response redaction for
86
+ > streaming until that lands.
87
+
88
+ ## Policy file (`traceredact.yml`)
89
+
90
+ Drop a `traceredact.yml` in your repo root (auto-discovered) or pass `--policy`:
91
+
92
+ ```yaml
93
+ entropy_threshold: 4.0
94
+ min_entropy_len: 20
95
+ disabled_detectors:
96
+ - pii.phone
97
+ allowlist:
98
+ - "noreply@example.com"
99
+ allow_patterns:
100
+ - ".*@example\\.com"
101
+ placeholder: "[REDACTED:{category}]"
102
+ hash_correlation: false # set true + hash_key to emit correlation tags
103
+ custom_patterns:
104
+ - id: custom.internal_user_id
105
+ category: pii
106
+ regex: "ACME-USR-[0-9]{8}"
107
+ confidence: 0.95
108
+ ```
109
+
110
+ See [`traceredact.yml`](./traceredact.yml) in this repo for a fully-commented example.
111
+
112
+ ## Detectors
113
+
114
+ **Secrets:** `secrets.openai_key`, `secrets.aws_access_key`,
115
+ `secrets.github_token`, `secrets.slack_token`, `secrets.slack_webhook`,
116
+ `secrets.google_api_key`, `secrets.stripe_key`, `secrets.sendgrid_key`,
117
+ `secrets.twilio_key`, `secrets.jwt`, `secrets.private_key`,
118
+ `secrets.basic_auth_url`, `secrets.env_assignment`, `secrets.high_entropy`.
119
+
120
+ **PII:** `pii.email`, `pii.credit_card` (Luhn), `pii.iban` (mod-97),
121
+ `pii.ipv4`, `pii.phone`.
122
+
123
+ Secret *pattern* hits are deterministic (confidence `1.0`); fuzzy heuristics
124
+ (entropy, phone, IP) carry lower confidence so policy thresholds can gate them.
125
+
126
+ ## Design & safety
127
+
128
+ - **Deterministic, no data retained.** Pure functions; nothing is stored.
129
+ - **Copy, never mutate.** Your objects are untouched.
130
+ - **ReDoS-safe.** Cheap literal prefilters gate bounded regexes; no nested
131
+ quantifiers; input length is capped.
132
+ - **Fail-closed.** Hash correlation without a key, or exceeding `max_depth`,
133
+ raises rather than silently leaking.
134
+
135
+ Detectors were hardened against adversarial evasion cases (see
136
+ `tests/test_evasion.py`).
137
+
138
+ ## License
139
+
140
+ Apache-2.0.
@@ -0,0 +1,118 @@
1
+ # traceredact
2
+
3
+ **Redact PII and secrets from AI prompts, agent traces and tool-call arguments
4
+ *before* they reach your loggers / observability backend.**
5
+
6
+ LLM apps log everything — prompts, agent traces, tool-call arguments — into
7
+ Langfuse / Helicone / Datadog / your own DB. Customer PII and API keys leak into
8
+ those traces. `traceredact` is a small, dependency-light library that detects
9
+ and redacts that data deterministically, in-process, before it leaves you.
10
+
11
+ It is **content-based**: it catches a `sk-…` key or a credit-card number even
12
+ when it sits under an innocuous JSON key — not just well-known field names.
13
+
14
+ > A missed secret is a real incident, so detection is treated as
15
+ > safety-critical: bounded (ReDoS-safe) patterns, entropy fallback, Luhn/IBAN
16
+ > validation, and adversarial evasion fixtures.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ pip install traceredact # or: uv add traceredact
22
+ ```
23
+
24
+ ## Usage (3 lines)
25
+
26
+ ```python
27
+ from traceredact import redact
28
+
29
+ result = redact({"args": {"email": "a@b.com", "key": "sk-1234567890abcdefABCDEFGH"}})
30
+ print(result.value) # {'args': {'email': '[REDACTED:pii]', 'key': '[REDACTED:secret]'}}
31
+ print(result.findings) # [Finding(detector_id='pii.email', json_path='args.email', ...), ...]
32
+ ```
33
+
34
+ `redact()` accepts a string, dict, list, or any nested mix. The input is never
35
+ mutated; `result.value` is a redacted copy and `result.findings` lists every hit
36
+ with its `detector_id`, `category`, `confidence`, `json_path` and `span`.
37
+
38
+ ### CLI (CI-gateable)
39
+
40
+ ```bash
41
+ traceredact scan ./logs/ # report findings as a table; exit 1 if any
42
+ traceredact scan trace.json -f json # machine-readable output for CI
43
+ traceredact redact trace.json -o redacted.json
44
+ ```
45
+
46
+ `scan` exits non-zero when anything is found, so you can gate a CI job on it.
47
+
48
+ ### SDK integrations
49
+
50
+ ```python
51
+ from openai import OpenAI
52
+ from traceredact.integrations.openai import wrap_openai
53
+
54
+ client = wrap_openai(OpenAI()) # prompts + completions now redacted in-flight
55
+ ```
56
+
57
+ Also: `traceredact.integrations.anthropic.wrap_anthropic(client)` and
58
+ `traceredact.integrations.langchain.RedactingCallbackHandler()`.
59
+
60
+ > **Limitation (MVP):** the wrappers patch the **synchronous, non-streaming**
61
+ > `create` call. Outbound prompts are always redacted, but **streamed**
62
+ > (`stream=True`) response *content* and **async** clients (`AsyncOpenAI`) are
63
+ > not yet redacted on the response side. Don't rely on response redaction for
64
+ > streaming until that lands.
65
+
66
+ ## Policy file (`traceredact.yml`)
67
+
68
+ Drop a `traceredact.yml` in your repo root (auto-discovered) or pass `--policy`:
69
+
70
+ ```yaml
71
+ entropy_threshold: 4.0
72
+ min_entropy_len: 20
73
+ disabled_detectors:
74
+ - pii.phone
75
+ allowlist:
76
+ - "noreply@example.com"
77
+ allow_patterns:
78
+ - ".*@example\\.com"
79
+ placeholder: "[REDACTED:{category}]"
80
+ hash_correlation: false # set true + hash_key to emit correlation tags
81
+ custom_patterns:
82
+ - id: custom.internal_user_id
83
+ category: pii
84
+ regex: "ACME-USR-[0-9]{8}"
85
+ confidence: 0.95
86
+ ```
87
+
88
+ See [`traceredact.yml`](./traceredact.yml) in this repo for a fully-commented example.
89
+
90
+ ## Detectors
91
+
92
+ **Secrets:** `secrets.openai_key`, `secrets.aws_access_key`,
93
+ `secrets.github_token`, `secrets.slack_token`, `secrets.slack_webhook`,
94
+ `secrets.google_api_key`, `secrets.stripe_key`, `secrets.sendgrid_key`,
95
+ `secrets.twilio_key`, `secrets.jwt`, `secrets.private_key`,
96
+ `secrets.basic_auth_url`, `secrets.env_assignment`, `secrets.high_entropy`.
97
+
98
+ **PII:** `pii.email`, `pii.credit_card` (Luhn), `pii.iban` (mod-97),
99
+ `pii.ipv4`, `pii.phone`.
100
+
101
+ Secret *pattern* hits are deterministic (confidence `1.0`); fuzzy heuristics
102
+ (entropy, phone, IP) carry lower confidence so policy thresholds can gate them.
103
+
104
+ ## Design & safety
105
+
106
+ - **Deterministic, no data retained.** Pure functions; nothing is stored.
107
+ - **Copy, never mutate.** Your objects are untouched.
108
+ - **ReDoS-safe.** Cheap literal prefilters gate bounded regexes; no nested
109
+ quantifiers; input length is capped.
110
+ - **Fail-closed.** Hash correlation without a key, or exceeding `max_depth`,
111
+ raises rather than silently leaking.
112
+
113
+ Detectors were hardened against adversarial evasion cases (see
114
+ `tests/test_evasion.py`).
115
+
116
+ ## License
117
+
118
+ Apache-2.0.
@@ -0,0 +1,66 @@
1
+ [project]
2
+ name = "traceredact"
3
+ version = "0.1.0"
4
+ description = "Redact PII and secrets from AI prompts, traces and tool-call arguments before they reach your loggers."
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = { text = "Apache-2.0" }
8
+ authors = [{ name = "traceredact contributors" }]
9
+ keywords = ["pii", "redaction", "secrets", "dlp", "llm", "observability", "privacy"]
10
+ dependencies = [
11
+ "pydantic>=2.6",
12
+ "typer>=0.12",
13
+ "pyyaml>=6.0",
14
+ ]
15
+
16
+ [project.optional-dependencies]
17
+ openai = ["openai>=1.0"]
18
+ anthropic = ["anthropic>=0.25"]
19
+ langchain = ["langchain-core>=0.2"]
20
+
21
+ [project.scripts]
22
+ traceredact = "traceredact.cli:app"
23
+
24
+ [project.urls]
25
+ Homepage = "https://github.com/traceredact/traceredact"
26
+ Issues = "https://github.com/traceredact/traceredact/issues"
27
+
28
+ [build-system]
29
+ requires = ["hatchling"]
30
+ build-backend = "hatchling.build"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/traceredact"]
34
+
35
+ [dependency-groups]
36
+ dev = [
37
+ "pytest>=8.0",
38
+ "ruff>=0.5",
39
+ "mypy>=1.10",
40
+ "types-pyyaml>=6.0",
41
+ ]
42
+
43
+ [tool.ruff]
44
+ line-length = 100
45
+ src = ["src", "tests"]
46
+
47
+ [tool.ruff.lint]
48
+ select = ["E", "F", "I", "UP", "B", "SIM"]
49
+
50
+ [tool.ruff.lint.per-file-ignores]
51
+ # typer's API requires calling typer.Option/Argument in parameter defaults.
52
+ "src/traceredact/cli.py" = ["B008"]
53
+
54
+ [tool.mypy]
55
+ python_version = "3.11"
56
+ strict = true
57
+ files = ["src/traceredact"]
58
+
59
+ [[tool.mypy.overrides]]
60
+ module = ["langchain_core.*"]
61
+ ignore_missing_imports = true
62
+
63
+ [tool.pytest.ini_options]
64
+ testpaths = ["tests"]
65
+ addopts = "-q"
66
+ pythonpath = ["src"]
@@ -0,0 +1,43 @@
1
+ """traceredact — redact PII & secrets from AI prompts, traces and tool-call args.
2
+
3
+ Quick start::
4
+
5
+ from traceredact import redact
6
+
7
+ result = redact({"args": {"email": "a@b.com", "key": "sk-abc123..."}})
8
+ result.value # -> {"args": {"email": "[REDACTED:pii]", "key": "[REDACTED:secret]"}}
9
+ result.findings # -> [Finding(json_path="args.email", ...), ...]
10
+ result.has_findings # -> True
11
+
12
+ Deterministic, no data retained. Configure via a :class:`Policy` (in code or a
13
+ ``traceredact.yml`` file).
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from typing import Any
19
+
20
+ from traceredact.detectors.base import Finding
21
+ from traceredact.engine import Engine, RedactionResult
22
+ from traceredact.policy import CustomPattern, Policy
23
+
24
+ __version__ = "0.1.0"
25
+
26
+ __all__ = [
27
+ "redact",
28
+ "Engine",
29
+ "RedactionResult",
30
+ "Finding",
31
+ "Policy",
32
+ "CustomPattern",
33
+ "__version__",
34
+ ]
35
+
36
+
37
+ def redact(value: Any, policy: Policy | None = None) -> RedactionResult:
38
+ """Redact ``value`` (str, dict, list, or nested mix) and return the result.
39
+
40
+ ``policy`` defaults to a sensible built-in policy. The input is never
41
+ mutated; ``result.value`` is a redacted copy.
42
+ """
43
+ return Engine(policy).redact(value)