colandix 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 (65) hide show
  1. colandix-0.1.0/.coverage +0 -0
  2. colandix-0.1.0/.github/workflows/docs.yml +49 -0
  3. colandix-0.1.0/.github/workflows/release.yml +23 -0
  4. colandix-0.1.0/.gitignore +22 -0
  5. colandix-0.1.0/.python-version +1 -0
  6. colandix-0.1.0/CHANGELOG.md +21 -0
  7. colandix-0.1.0/LICENSE +21 -0
  8. colandix-0.1.0/PKG-INFO +278 -0
  9. colandix-0.1.0/README.md +247 -0
  10. colandix-0.1.0/colandix/__init__.py +21 -0
  11. colandix-0.1.0/colandix/compliance.py +185 -0
  12. colandix-0.1.0/colandix/detectors/__init__.py +1 -0
  13. colandix-0.1.0/colandix/detectors/base.py +123 -0
  14. colandix-0.1.0/colandix/detectors/entropy.py +336 -0
  15. colandix-0.1.0/colandix/detectors/injection.py +166 -0
  16. colandix-0.1.0/colandix/detectors/ner.py +244 -0
  17. colandix-0.1.0/colandix/detectors/regex.py +272 -0
  18. colandix-0.1.0/colandix/detectors/topic.py +87 -0
  19. colandix-0.1.0/colandix/exceptions.py +16 -0
  20. colandix-0.1.0/colandix/logger.py +82 -0
  21. colandix-0.1.0/colandix/pipeline.py +173 -0
  22. colandix-0.1.0/colandix/profiles/__init__.py +1 -0
  23. colandix-0.1.0/colandix/profiles/dev.yaml +48 -0
  24. colandix-0.1.0/colandix/profiles/generique.yaml +26 -0
  25. colandix-0.1.0/colandix/profiles/juridique.yaml +34 -0
  26. colandix-0.1.0/colandix/profiles/loader.py +124 -0
  27. colandix-0.1.0/colandix/profiles/rh.yaml +38 -0
  28. colandix-0.1.0/colandix/profiles/sante.yaml +39 -0
  29. colandix-0.1.0/colandix/profiles/strict.yaml +47 -0
  30. colandix-0.1.0/colandix/redaction.py +40 -0
  31. colandix-0.1.0/colandix/result.py +107 -0
  32. colandix-0.1.0/colandix/scoring.py +206 -0
  33. colandix-0.1.0/docs/architecture.md +194 -0
  34. colandix-0.1.0/docs/compliance.md +146 -0
  35. colandix-0.1.0/docs/contributing.md +65 -0
  36. colandix-0.1.0/docs/index.md +77 -0
  37. colandix-0.1.0/docs/quickstart.md +76 -0
  38. colandix-0.1.0/docs/stylesheets/extra.css +121 -0
  39. colandix-0.1.0/docs/testing.md +116 -0
  40. colandix-0.1.0/docs/triggers-par-profil.md +185 -0
  41. colandix-0.1.0/examples/admin_douanes.yaml +20 -0
  42. colandix-0.1.0/examples/basic_usage.py +73 -0
  43. colandix-0.1.0/examples/custom_profile.py +28 -0
  44. colandix-0.1.0/examples/with_openai.py +63 -0
  45. colandix-0.1.0/mkdocs.yml +77 -0
  46. colandix-0.1.0/notebooks/demo_colandix.ipynb +755 -0
  47. colandix-0.1.0/notebooks/tests_colandix.ipynb +1883 -0
  48. colandix-0.1.0/pyproject.toml +60 -0
  49. colandix-0.1.0/tests/__init__.py +1 -0
  50. colandix-0.1.0/tests/conftest.py +1 -0
  51. colandix-0.1.0/tests/test_compliance.py +138 -0
  52. colandix-0.1.0/tests/test_detectors/__init__.py +1 -0
  53. colandix-0.1.0/tests/test_detectors/test_base.py +135 -0
  54. colandix-0.1.0/tests/test_detectors/test_entropy.py +268 -0
  55. colandix-0.1.0/tests/test_detectors/test_injection.py +221 -0
  56. colandix-0.1.0/tests/test_detectors/test_ner.py +219 -0
  57. colandix-0.1.0/tests/test_detectors/test_regex.py +587 -0
  58. colandix-0.1.0/tests/test_detectors/test_topic.py +131 -0
  59. colandix-0.1.0/tests/test_logger.py +137 -0
  60. colandix-0.1.0/tests/test_pipeline.py +469 -0
  61. colandix-0.1.0/tests/test_profiles.py +139 -0
  62. colandix-0.1.0/tests/test_redaction.py +334 -0
  63. colandix-0.1.0/tests/test_result.py +263 -0
  64. colandix-0.1.0/tests/test_scoring.py +333 -0
  65. colandix-0.1.0/uv.lock +2706 -0
Binary file
@@ -0,0 +1,49 @@
1
+ name: Docs
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+
7
+ concurrency:
8
+ group: pages
9
+ cancel-in-progress: false
10
+
11
+ permissions:
12
+ contents: read
13
+ pages: write
14
+ id-token: write
15
+
16
+ jobs:
17
+ build:
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ with:
22
+ fetch-depth: 0
23
+
24
+ - uses: astral-sh/setup-uv@v5
25
+
26
+ - name: Install dev dependencies
27
+ run: uv sync --all-groups
28
+
29
+ - name: Setup Pages
30
+ uses: actions/configure-pages@v5
31
+
32
+ - name: Build docs
33
+ run: uv run mkdocs build --strict
34
+
35
+ - name: Upload artifact
36
+ uses: actions/upload-pages-artifact@v3
37
+ with:
38
+ path: site/
39
+
40
+ deploy:
41
+ runs-on: ubuntu-latest
42
+ needs: build
43
+ environment:
44
+ name: github-pages
45
+ url: ${{ steps.deployment.outputs.page_url }}
46
+ steps:
47
+ - name: Deploy to GitHub Pages
48
+ id: deployment
49
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,23 @@
1
+ name: Release
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ permissions:
8
+ contents: read
9
+ id-token: write
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+
17
+ - uses: astral-sh/setup-uv@v5
18
+
19
+ - name: Build package
20
+ run: uv build
21
+
22
+ - name: Publish to PyPI
23
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,22 @@
1
+ **/.venv/
2
+ dist/
3
+ build/
4
+ site/
5
+ *.egg-info/
6
+ __pycache__/
7
+ **/__pycache__/
8
+ *.py[cod]
9
+ *$py.class
10
+
11
+ # IDEs
12
+ .vscode/
13
+ .idea/
14
+
15
+ # Caches
16
+ **/.ruff_cache/
17
+ **/.mypy_cache/
18
+ **/.pytest_cache/
19
+ **/.ipynb_checkpoints/
20
+ **/.DS_Store
21
+
22
+ init-repo.sh
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.1.0] - 2026-05-06
11
+
12
+ ### Added
13
+
14
+ - `GuardPipeline` and scanner API for input/output text, aligned with **ANSSI-PA-102**-style guidance
15
+ - Detectors: regex (PII, secrets, identifiers), entropy, prompt-injection heuristics, optional spaCy NER, topic checks
16
+ - YAML profiles (`generique`, `strict`, domain variants) and compliance helpers
17
+ - Redaction, scoring, and structured scan results
18
+ - Documentation site (MkDocs Material) and test suite
19
+
20
+ [Unreleased]: https://github.com/GrosGradient/colandix/compare/v0.1.0...HEAD
21
+ [0.1.0]: https://github.com/GrosGradient/colandix/releases/tag/v0.1.0
colandix-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gros Gradient
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,278 @@
1
+ Metadata-Version: 2.4
2
+ Name: colandix
3
+ Version: 0.1.0
4
+ Summary: ANSSI-PA-102 compliance layer for LLM inference. Runs locally. No network calls in the core path.
5
+ Project-URL: Homepage, https://grosgradient.github.io/colandix
6
+ Project-URL: Repository, https://github.com/GrosGradient/colandix
7
+ Project-URL: Bug Tracker, https://github.com/GrosGradient/colandix/issues
8
+ Project-URL: Documentation, https://grosgradient.github.io/colandix
9
+ Author: Gros Gradient
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Requires-Python: >=3.10
13
+ Requires-Dist: pyyaml>=6.0
14
+ Provides-Extra: ner
15
+ Requires-Dist: spacy<4.0,>=3.7; extra == 'ner'
16
+ Provides-Extra: ner-all
17
+ Requires-Dist: fr-core-news-md>=3.7; extra == 'ner-all'
18
+ Provides-Extra: ner-de
19
+ Requires-Dist: spacy<4.0,>=3.7; extra == 'ner-de'
20
+ Provides-Extra: ner-en
21
+ Requires-Dist: spacy<4.0,>=3.7; extra == 'ner-en'
22
+ Provides-Extra: ner-es
23
+ Requires-Dist: spacy<4.0,>=3.7; extra == 'ner-es'
24
+ Provides-Extra: ner-fr
25
+ Requires-Dist: fr-core-news-md>=3.7; extra == 'ner-fr'
26
+ Provides-Extra: ner-it
27
+ Requires-Dist: spacy<4.0,>=3.7; extra == 'ner-it'
28
+ Provides-Extra: ner-pt
29
+ Requires-Dist: spacy<4.0,>=3.7; extra == 'ner-pt'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Colandix
33
+
34
+ > Sanitize text before and after your LLM. Runs **locally**. No network calls in the library.
35
+
36
+ > Maps to French national guidance **ANSSI-PA-102** for generative AI security.
37
+
38
+ **Colandix** is a filtering layer that sits at the boundary between your application and the model. Safe content passes through. PII, secrets, and injection attempts do not reach the model.
39
+
40
+ [![Tests](https://img.shields.io/badge/tests-362%20collected-green)](docs/testing.md)
41
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](.python-version)
42
+ [![PyPI](https://img.shields.io/badge/pypi-colandix-blue)](https://pypi.org/project/colandix/)
43
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
44
+
45
+ ---
46
+
47
+ ## Install
48
+
49
+ ```bash
50
+ pip install colandix
51
+ ```
52
+
53
+ Development setup with `uv`:
54
+
55
+ ```bash
56
+ uv sync --all-groups
57
+ ```
58
+
59
+ ### Optional pipelines (NER / SpaCy)
60
+
61
+ SpaCy pipelines are optional. Without them, regex, entropy, injection, and topic detectors still run; NER stays inactive.
62
+
63
+ | Extra | What it installs |
64
+ | :--- | :--- |
65
+ | `ner` | `spacy` only; then `python -m spacy download <pipeline>` (see [spacy.io/models](https://spacy.io/models)) |
66
+ | `ner-fr` | `fr_core_news_md` via PyPI (matches shipped profiles) |
67
+ | `ner-de`, `ner-en`, `ner-es`, `ner-it`, `ner-pt` | `spacy` only; install the pipeline with `python -m spacy download de_core_news_md` (etc.) |
68
+ | `ner-all` | `fr_core_news_md` wheel only; use `python -m spacy download` for other languages |
69
+
70
+ ```bash
71
+ pip install "colandix[ner-fr]"
72
+ # or
73
+ pip install "colandix[ner]" && python -m spacy download fr_core_news_md
74
+ ```
75
+
76
+ Bundled profiles default to `fr_core_news_md`. For another language, set `extra.model` and `entities` in your YAML (English uses `PERSON`, not `PER`).
77
+
78
+ ---
79
+
80
+ ## Quickstart
81
+
82
+ ```python
83
+ from colandix import GuardPipeline
84
+
85
+ guard = GuardPipeline(profile="generique")
86
+ res_in = guard.scan_input("my prompt")
87
+
88
+ response = call_llm(res_in.sanitized_text)
89
+ guard.scan_output(response)
90
+ ```
91
+
92
+ Tutorial: [notebooks/demo_colandix.ipynb](notebooks/demo_colandix.ipynb).
93
+
94
+ ---
95
+
96
+ ## What it does
97
+
98
+ The **colandix** library sits between your app and the model.
99
+
100
+ ```mermaid
101
+ flowchart LR
102
+ userInput[User_input] --> scanIn[scan_input]
103
+ scanIn --> sanitized[sanitized_text]
104
+ sanitized --> llm[LLM]
105
+ llm --> modelOutput[Model_output]
106
+ modelOutput --> scanOut[scan_output]
107
+ scanIn --> decisionIn["action + events"]
108
+ scanOut --> decisionOut["action + events"]
109
+ ```
110
+
111
+ - **Scans** inputs and outputs with configurable detectors (PII, secrets, entropy, prompt injection, topics, optional NER).
112
+ - **Rewrites** sensitive spans in `sanitized_text` with typed tags (`[EMAIL_REDACTED]`, `[PHONE_REDACTED]`, `[PERSON_REDACTED]`, etc.).
113
+ - **Decides** an aggregate `action`: `pass`, `warn`, `human_review`, or `block`.
114
+ - **Logs** pseudonymized metadata; no raw prompts in logs.
115
+
116
+ ---
117
+
118
+ ## What a scan returns
119
+
120
+ | Field | Role |
121
+ | :--- | :--- |
122
+ | `result.action` | Aggregate decision (`Action` enum). |
123
+ | `result.sanitized_text` | Text to send to the LLM after masking. |
124
+ | `result.events` | Audit trail (evidence truncated for SIEM). |
125
+ | `result.blocked` | `True` when `action == block`. |
126
+ | `guard.find_all_candidates(text)` | Debug: list possible regex/NER hits. |
127
+
128
+ Injection and entropy detectors affect the decision only; they do not rewrite `sanitized_text`.
129
+
130
+ Redaction rules: [`colandix/redaction.py`](colandix/redaction.py), [Architecture](docs/architecture.md).
131
+
132
+ ---
133
+
134
+ ## Profiles
135
+
136
+ | Profile | Use case |
137
+ | :--- | :--- |
138
+ | `generique` | Everyday PII + injection. |
139
+ | `strict` | Broad PII and secrets + NER (requires SpaCy pipeline). |
140
+ | `sante` | Healthcare PII + medical topic guardrails. |
141
+ | `dev` | Credentials, secrets, sensitive dev topics. |
142
+ | `rh` | HR-sensitive wording and data. |
143
+ | `juridique` | Legal / confidentiality patterns. |
144
+
145
+ YAML sources: [`colandix/profiles/`](colandix/profiles/). Trigger reference: [docs/triggers-par-profil.md](docs/triggers-par-profil.md).
146
+
147
+ ---
148
+
149
+ ## ANSSI PA-102 alignment
150
+
151
+ Scope: content filtering and rewriting at the model boundary.
152
+
153
+ Official guide (PDF): [ANSSI generative AI security recommendations](https://messervices.cyber.gouv.fr/documents-guides/Recommandations_de_s%C3%A9curit%C3%A9_pour_un_syst%C3%A8me_d_IA_g%C3%A9n%C3%A9rative.pdf).
154
+
155
+ | Ref | Topic | Coverage | Status |
156
+ | :--- | :--- | :--- | :--- |
157
+ | **R25** | Input/output filtering | Regex, NER, entropy, injection, `sanitized_text`. | Yes |
158
+ | **R26** | Application interactions | `TopicDetector` (`allowed` / `blocked`). | Partial |
159
+ | **R27** | Human control | `Action.HUMAN_REVIEW`. | Partial |
160
+ | **R29** | Logging | Structured logger, no raw user text. | Partial |
161
+ | **R31** | Critical modules | Profile separation (`dev`, `juridique`, ...). | Partial |
162
+ | **R34** | Sovereign hosting | Runs offline in the orchestration path. | Yes |
163
+
164
+ Controls outside this package (TLS, IAM, org processes): [docs/compliance.md](docs/compliance.md).
165
+
166
+ ---
167
+
168
+ ## LLM integration
169
+
170
+ ```python
171
+ from colandix import GuardPipeline
172
+ from colandix.exceptions import ColandixBlockedError
173
+
174
+ guard = GuardPipeline(profile="generique")
175
+
176
+ try:
177
+ res_in = guard.scan_input(prompt, raise_on_block=True)
178
+ response = call_llm(res_in.sanitized_text)
179
+ guard.scan_output(response, raise_on_block=True)
180
+ except ColandixBlockedError:
181
+ return "Content blocked."
182
+ ```
183
+
184
+ Replace `call_llm` with your SDK. Use `raise_on_block=False` to branch on `result.action` yourself.
185
+
186
+ ---
187
+
188
+ ## Custom YAML
189
+
190
+ ```python
191
+ guard = GuardPipeline(profile_path="/path/to/profile.yaml")
192
+ ```
193
+
194
+ Start from [`colandix/profiles/`](colandix/profiles/). Detector keys: [docs/architecture.md](docs/architecture.md).
195
+
196
+ ---
197
+
198
+ ## Compliance report
199
+
200
+ ```python
201
+ from colandix.compliance import print_report
202
+
203
+ print_report(guard.compliance_report())
204
+ ```
205
+
206
+ ---
207
+
208
+ ## Documentation
209
+
210
+ - [Site](https://grosgradient.github.io/colandix) (GitHub Pages)
211
+ - [Architecture](docs/architecture.md)
212
+ - [Triggers by profile](docs/triggers-par-profil.md)
213
+ - [Testing](docs/testing.md)
214
+ - [Compliance (ANSSI)](docs/compliance.md)
215
+
216
+ ---
217
+
218
+ ## Docs (local preview)
219
+
220
+ ```bash
221
+ uv run mkdocs serve # http://127.0.0.1:8000, reloads on save
222
+ uv run mkdocs build # static output in site/ (gitignored; CI rebuilds on deploy)
223
+ ```
224
+
225
+ `mkdocstrings` requires the package to be importable at build time. `uv sync --all-groups` installs `colandix` in dev mode alongside the docs dependencies, matching what the GitHub Actions workflow does.
226
+
227
+ ---
228
+
229
+ ## Pre-deployment checklist
230
+
231
+ ```bash
232
+ uv run pytest tests/ -q
233
+ uv run ruff check colandix tests
234
+ uv run mypy colandix
235
+ uv run mkdocs build
236
+ uv build
237
+ ```
238
+
239
+ Manual checks:
240
+
241
+ - [ ] Version in `pyproject.toml` matches `colandix/__init__.py`.
242
+ - [ ] [docs/compliance.md](docs/compliance.md) updated if detectors or ANSSI scope changed.
243
+ - [ ] `pytest tests/test_detectors/test_ner.py -v` passes with `fr_core_news_md` installed.
244
+ - [ ] `notebooks/demo_colandix.ipynb` runs top-to-bottom without errors.
245
+ - [ ] `docs.yml` workflow completes on a push to `main`.
246
+
247
+ ---
248
+
249
+ ## Publishing (maintainers)
250
+
251
+ ```bash
252
+ uv build
253
+ uv publish
254
+ ```
255
+
256
+ Set PyPI tokens and bump `pyproject.toml` version before publishing.
257
+
258
+ ---
259
+
260
+ ## Contributing
261
+
262
+ 1. Fork the repo.
263
+ 2. `git checkout -b feature/your-change`
264
+ 3. `uv run pytest tests/` (~362 cases)
265
+ 4. Open a Pull Request.
266
+
267
+ ---
268
+
269
+ ## License
270
+
271
+ MIT — see [LICENSE](LICENSE).
272
+ © 2026 [Gros Gradient](https://www.grosgradient.com/)
273
+
274
+ ---
275
+
276
+ ## Pour les équipes ANSSI et security reviewers
277
+
278
+ La bibliothèque **colandix** est développée par [Gros Gradient](https://www.grosgradient.com/). La cartographie **R25–R35**, `sanitized_text` / `action`, et le périmètre bibliothèque sont dans [docs/compliance.md](docs/compliance.md) (anglais). Le guide officiel ANSSI (IA générative) reste la référence réglementaire en français : [PDF recommandations ANSSI](https://messervices.cyber.gouv.fr/documents-guides/Recommandations_de_s%C3%A9curit%C3%A9_pour_un_syst%C3%A8me_d_IA_g%C3%A9n%C3%A9rative.pdf).
@@ -0,0 +1,247 @@
1
+ # Colandix
2
+
3
+ > Sanitize text before and after your LLM. Runs **locally**. No network calls in the library.
4
+
5
+ > Maps to French national guidance **ANSSI-PA-102** for generative AI security.
6
+
7
+ **Colandix** is a filtering layer that sits at the boundary between your application and the model. Safe content passes through. PII, secrets, and injection attempts do not reach the model.
8
+
9
+ [![Tests](https://img.shields.io/badge/tests-362%20collected-green)](docs/testing.md)
10
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](.python-version)
11
+ [![PyPI](https://img.shields.io/badge/pypi-colandix-blue)](https://pypi.org/project/colandix/)
12
+ [![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
13
+
14
+ ---
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pip install colandix
20
+ ```
21
+
22
+ Development setup with `uv`:
23
+
24
+ ```bash
25
+ uv sync --all-groups
26
+ ```
27
+
28
+ ### Optional pipelines (NER / SpaCy)
29
+
30
+ SpaCy pipelines are optional. Without them, regex, entropy, injection, and topic detectors still run; NER stays inactive.
31
+
32
+ | Extra | What it installs |
33
+ | :--- | :--- |
34
+ | `ner` | `spacy` only; then `python -m spacy download <pipeline>` (see [spacy.io/models](https://spacy.io/models)) |
35
+ | `ner-fr` | `fr_core_news_md` via PyPI (matches shipped profiles) |
36
+ | `ner-de`, `ner-en`, `ner-es`, `ner-it`, `ner-pt` | `spacy` only; install the pipeline with `python -m spacy download de_core_news_md` (etc.) |
37
+ | `ner-all` | `fr_core_news_md` wheel only; use `python -m spacy download` for other languages |
38
+
39
+ ```bash
40
+ pip install "colandix[ner-fr]"
41
+ # or
42
+ pip install "colandix[ner]" && python -m spacy download fr_core_news_md
43
+ ```
44
+
45
+ Bundled profiles default to `fr_core_news_md`. For another language, set `extra.model` and `entities` in your YAML (English uses `PERSON`, not `PER`).
46
+
47
+ ---
48
+
49
+ ## Quickstart
50
+
51
+ ```python
52
+ from colandix import GuardPipeline
53
+
54
+ guard = GuardPipeline(profile="generique")
55
+ res_in = guard.scan_input("my prompt")
56
+
57
+ response = call_llm(res_in.sanitized_text)
58
+ guard.scan_output(response)
59
+ ```
60
+
61
+ Tutorial: [notebooks/demo_colandix.ipynb](notebooks/demo_colandix.ipynb).
62
+
63
+ ---
64
+
65
+ ## What it does
66
+
67
+ The **colandix** library sits between your app and the model.
68
+
69
+ ```mermaid
70
+ flowchart LR
71
+ userInput[User_input] --> scanIn[scan_input]
72
+ scanIn --> sanitized[sanitized_text]
73
+ sanitized --> llm[LLM]
74
+ llm --> modelOutput[Model_output]
75
+ modelOutput --> scanOut[scan_output]
76
+ scanIn --> decisionIn["action + events"]
77
+ scanOut --> decisionOut["action + events"]
78
+ ```
79
+
80
+ - **Scans** inputs and outputs with configurable detectors (PII, secrets, entropy, prompt injection, topics, optional NER).
81
+ - **Rewrites** sensitive spans in `sanitized_text` with typed tags (`[EMAIL_REDACTED]`, `[PHONE_REDACTED]`, `[PERSON_REDACTED]`, etc.).
82
+ - **Decides** an aggregate `action`: `pass`, `warn`, `human_review`, or `block`.
83
+ - **Logs** pseudonymized metadata; no raw prompts in logs.
84
+
85
+ ---
86
+
87
+ ## What a scan returns
88
+
89
+ | Field | Role |
90
+ | :--- | :--- |
91
+ | `result.action` | Aggregate decision (`Action` enum). |
92
+ | `result.sanitized_text` | Text to send to the LLM after masking. |
93
+ | `result.events` | Audit trail (evidence truncated for SIEM). |
94
+ | `result.blocked` | `True` when `action == block`. |
95
+ | `guard.find_all_candidates(text)` | Debug: list possible regex/NER hits. |
96
+
97
+ Injection and entropy detectors affect the decision only; they do not rewrite `sanitized_text`.
98
+
99
+ Redaction rules: [`colandix/redaction.py`](colandix/redaction.py), [Architecture](docs/architecture.md).
100
+
101
+ ---
102
+
103
+ ## Profiles
104
+
105
+ | Profile | Use case |
106
+ | :--- | :--- |
107
+ | `generique` | Everyday PII + injection. |
108
+ | `strict` | Broad PII and secrets + NER (requires SpaCy pipeline). |
109
+ | `sante` | Healthcare PII + medical topic guardrails. |
110
+ | `dev` | Credentials, secrets, sensitive dev topics. |
111
+ | `rh` | HR-sensitive wording and data. |
112
+ | `juridique` | Legal / confidentiality patterns. |
113
+
114
+ YAML sources: [`colandix/profiles/`](colandix/profiles/). Trigger reference: [docs/triggers-par-profil.md](docs/triggers-par-profil.md).
115
+
116
+ ---
117
+
118
+ ## ANSSI PA-102 alignment
119
+
120
+ Scope: content filtering and rewriting at the model boundary.
121
+
122
+ Official guide (PDF): [ANSSI generative AI security recommendations](https://messervices.cyber.gouv.fr/documents-guides/Recommandations_de_s%C3%A9curit%C3%A9_pour_un_syst%C3%A8me_d_IA_g%C3%A9n%C3%A9rative.pdf).
123
+
124
+ | Ref | Topic | Coverage | Status |
125
+ | :--- | :--- | :--- | :--- |
126
+ | **R25** | Input/output filtering | Regex, NER, entropy, injection, `sanitized_text`. | Yes |
127
+ | **R26** | Application interactions | `TopicDetector` (`allowed` / `blocked`). | Partial |
128
+ | **R27** | Human control | `Action.HUMAN_REVIEW`. | Partial |
129
+ | **R29** | Logging | Structured logger, no raw user text. | Partial |
130
+ | **R31** | Critical modules | Profile separation (`dev`, `juridique`, ...). | Partial |
131
+ | **R34** | Sovereign hosting | Runs offline in the orchestration path. | Yes |
132
+
133
+ Controls outside this package (TLS, IAM, org processes): [docs/compliance.md](docs/compliance.md).
134
+
135
+ ---
136
+
137
+ ## LLM integration
138
+
139
+ ```python
140
+ from colandix import GuardPipeline
141
+ from colandix.exceptions import ColandixBlockedError
142
+
143
+ guard = GuardPipeline(profile="generique")
144
+
145
+ try:
146
+ res_in = guard.scan_input(prompt, raise_on_block=True)
147
+ response = call_llm(res_in.sanitized_text)
148
+ guard.scan_output(response, raise_on_block=True)
149
+ except ColandixBlockedError:
150
+ return "Content blocked."
151
+ ```
152
+
153
+ Replace `call_llm` with your SDK. Use `raise_on_block=False` to branch on `result.action` yourself.
154
+
155
+ ---
156
+
157
+ ## Custom YAML
158
+
159
+ ```python
160
+ guard = GuardPipeline(profile_path="/path/to/profile.yaml")
161
+ ```
162
+
163
+ Start from [`colandix/profiles/`](colandix/profiles/). Detector keys: [docs/architecture.md](docs/architecture.md).
164
+
165
+ ---
166
+
167
+ ## Compliance report
168
+
169
+ ```python
170
+ from colandix.compliance import print_report
171
+
172
+ print_report(guard.compliance_report())
173
+ ```
174
+
175
+ ---
176
+
177
+ ## Documentation
178
+
179
+ - [Site](https://grosgradient.github.io/colandix) (GitHub Pages)
180
+ - [Architecture](docs/architecture.md)
181
+ - [Triggers by profile](docs/triggers-par-profil.md)
182
+ - [Testing](docs/testing.md)
183
+ - [Compliance (ANSSI)](docs/compliance.md)
184
+
185
+ ---
186
+
187
+ ## Docs (local preview)
188
+
189
+ ```bash
190
+ uv run mkdocs serve # http://127.0.0.1:8000, reloads on save
191
+ uv run mkdocs build # static output in site/ (gitignored; CI rebuilds on deploy)
192
+ ```
193
+
194
+ `mkdocstrings` requires the package to be importable at build time. `uv sync --all-groups` installs `colandix` in dev mode alongside the docs dependencies, matching what the GitHub Actions workflow does.
195
+
196
+ ---
197
+
198
+ ## Pre-deployment checklist
199
+
200
+ ```bash
201
+ uv run pytest tests/ -q
202
+ uv run ruff check colandix tests
203
+ uv run mypy colandix
204
+ uv run mkdocs build
205
+ uv build
206
+ ```
207
+
208
+ Manual checks:
209
+
210
+ - [ ] Version in `pyproject.toml` matches `colandix/__init__.py`.
211
+ - [ ] [docs/compliance.md](docs/compliance.md) updated if detectors or ANSSI scope changed.
212
+ - [ ] `pytest tests/test_detectors/test_ner.py -v` passes with `fr_core_news_md` installed.
213
+ - [ ] `notebooks/demo_colandix.ipynb` runs top-to-bottom without errors.
214
+ - [ ] `docs.yml` workflow completes on a push to `main`.
215
+
216
+ ---
217
+
218
+ ## Publishing (maintainers)
219
+
220
+ ```bash
221
+ uv build
222
+ uv publish
223
+ ```
224
+
225
+ Set PyPI tokens and bump `pyproject.toml` version before publishing.
226
+
227
+ ---
228
+
229
+ ## Contributing
230
+
231
+ 1. Fork the repo.
232
+ 2. `git checkout -b feature/your-change`
233
+ 3. `uv run pytest tests/` (~362 cases)
234
+ 4. Open a Pull Request.
235
+
236
+ ---
237
+
238
+ ## License
239
+
240
+ MIT — see [LICENSE](LICENSE).
241
+ © 2026 [Gros Gradient](https://www.grosgradient.com/)
242
+
243
+ ---
244
+
245
+ ## Pour les équipes ANSSI et security reviewers
246
+
247
+ La bibliothèque **colandix** est développée par [Gros Gradient](https://www.grosgradient.com/). La cartographie **R25–R35**, `sanitized_text` / `action`, et le périmètre bibliothèque sont dans [docs/compliance.md](docs/compliance.md) (anglais). Le guide officiel ANSSI (IA générative) reste la référence réglementaire en français : [PDF recommandations ANSSI](https://messervices.cyber.gouv.fr/documents-guides/Recommandations_de_s%C3%A9curit%C3%A9_pour_un_syst%C3%A8me_d_IA_g%C3%A9n%C3%A9rative.pdf).
@@ -0,0 +1,21 @@
1
+ from colandix.exceptions import ColandixBlockedError
2
+ from colandix.pipeline import GuardPipeline
3
+ from colandix.profiles.loader import get_profile_metadata, list_profiles
4
+ from colandix.redaction import REDACTION_TAGS, get_redaction_tag
5
+ from colandix.result import Action, PipelineConfig, ScanDirection, ScanResult
6
+
7
+ __version__ = "0.1.0"
8
+ __author__ = "Gros Gradient"
9
+
10
+ __all__ = [
11
+ "GuardPipeline",
12
+ "ColandixBlockedError",
13
+ "ScanResult",
14
+ "Action",
15
+ "ScanDirection",
16
+ "PipelineConfig",
17
+ "list_profiles",
18
+ "get_profile_metadata",
19
+ "REDACTION_TAGS",
20
+ "get_redaction_tag",
21
+ ]