Test PIIMiddleware stream redaction at every chunk split
Submission checklist
- This is a feature request, not a bug report or usage question.
- I added a clear and descriptive title that summarizes the feature request.
- I used the GitHub search to find a similar feature request and didn't find it.
- I checked the LangChain documentation and API reference to see if this feature already exists.
- This is not related to the langchain-community package.
Package (Required)
- langchain
- langchain-openai
- langchain-anthropic
- langchain-classic
- langchain-core
- langchain-model-profiles
- langchain-tests
- langchain-text-splitters
- langchain-chroma
- langchain-deepseek
- langchain-exa
- langchain-fireworks
- langchain-groq
- langchain-huggingface
- langchain-mistralai
- langchain-nomic
- langchain-ollama
- langchain-openrouter
- langchain-perplexity
- langchain-qdrant
- langchain-typesafe
- langchain-xai
- Other / not sure / general
Feature Description
One unit test for PIIMiddleware's in-flight stream redaction (#37616) that checks every chunk split point, not a few chosen ones.
Use Case
#37616 redacts streamed text in flight. Its tests check a few chosen splits (test_pii_split_across_deltas_is_caught, test_pii_straddling_lookback_boundary_is_caught, test_credit_card_split_across_whitespace_is_caught). A later change to the lookback logic that breaks a different split could go unnoticed.
Proposed Solution
Add one test to test_pii.py that streams a short text through _PIIStreamTransformer split into two deltas at every position, and checks the output matches the unsplit stream. The text has an email, a card number and a value next to non-ASCII text. About 20 lines, test-only, no new dependencies. When it fails it names the split.
@mdrxy would you take this? If yes, please assign me and I'll open the PR.
Alternatives Considered
No response
Additional Context
Related: #35011, #37616
Social handles (optional)
No response
Source: langchain-ai/langchain