# BR-AGT-02

Quand le modèle écrit un jeton que piighost n'a jamais émis, alors la réponse est refusée par défaut, avec Deanonymized text holds tokens the pipeline never issued.

Défini dans [Brancher la protection sur un agent et ses outils](https://docs.piighost.dev/fr/domain/integrations/agents-and-tools/#br-agt-02).

## Où vit la règle

- [`replace()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/_deidentify.py#L127)
- [`TextDeidentifier.deanonymize_value()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/_deidentify.py#L140)
- [`TextDeidentifier.anonymize_value()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/_deidentify.py#L150)
- [`TextDeidentifier`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/_deidentify.py#L53)

## Tests directs

- [`tests/integrations/test_deidentify_stream.py::test_invented_token_is_dropped`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify_stream.py#L73)
- [`tests/integrations/test_deidentify_stream.py::test_invented_token_raises`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify_stream.py#L80)
- [`tests/integrations/test_deidentify_stream.py::test_literal_text_streams_through`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify_stream.py#L59)
- [`tests/integrations/test_deidentify_stream.py::test_token_split_across_chunks_is_restored`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify_stream.py#L51)
- [`tests/integrations/test_deidentify_stream.py::test_trailing_incomplete_token_is_flushed`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify_stream.py#L66)
- [`tests/integrations/test_deidentify.py::TestAnonymize::test_replaces_pii_with_a_token`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L46)
- [`tests/integrations/test_deidentify.py::TestConstruction::test_a_factory_that_shares_tokens_is_refused`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L95)
- [`tests/integrations/test_deidentify.py::TestConstruction::test_a_pipeline_without_a_recognizer_is_refused`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L79)
- [`tests/integrations/test_deidentify.py::TestConstruction::test_a_reversible_factory_is_accepted`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L116)
- [`tests/integrations/test_deidentify.py::TestDeanonymize::test_round_trips_a_message`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L53)
- [`tests/integrations/test_deidentify.py::TestInventedStrategy::test_drop_removes_an_invented_token`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L66)
- [`tests/integrations/test_deidentify.py::TestInventedStrategy::test_keep_leaves_an_invented_token`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L61)
- [`tests/integrations/test_deidentify.py::TestInventedStrategy::test_raise_refuses_an_invented_token`](https://github.com/Athroniaeth/piighost/blob/master/tests/integrations/test_deidentify.py#L71)

## Tests indirects

Aucun test indirect trouvé.

## Utilisé par

- [`TextDeidentifier.deanonymize_stream()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/_deidentify.py#L114)
- [`ChunkedDetector.detect()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/components/detector/chunked.py#L36)
- [`BaseNERDetector.detect()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/components/detector/ner/base.py#L87)
- [`BaseNERDetector._gather_raw()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/components/detector/ner/base.py#L99)
- [`BaseNERDetector._reread()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/components/detector/ner/base.py#L131)
- [`BaseAnonymizationPipeline._guard()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/pipeline/base.py#L349)
- [`PIIAnonymizationMiddleware.__init__()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/langchain/middleware.py#L123)
- [`PIIQueryEngine.__init__()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/llama_index/query_engine.py#L43)
- [`pii_hooks()`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/pydantic_ai/hooks.py#L40)
- [`PIIAnonymizationMiddleware`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/langchain/middleware.py#L108)
- [`PIIQueryEngine`](https://github.com/Athroniaeth/piighost/blob/master/src/piighost/integrations/llama_index/query_engine.py#L30)

Lu dans le graphe du code que construit graphify, aux emplacements que donne la documentation métier.
