apply_strategy() — langchain Function Reference
Architecture documentation for the apply_strategy() function in _redaction.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a830b2dc_75ff_a1e7_d25c_7de2223efe55["apply_strategy()"] be639235_9a02_cc2d_5a7d_637d822fb3b3["_redaction.py"] a830b2dc_75ff_a1e7_d25c_7de2223efe55 -->|defined in| be639235_9a02_cc2d_5a7d_637d822fb3b3 fae00189_d2f4_7398_49ea_3100608cdf41["apply()"] fae00189_d2f4_7398_49ea_3100608cdf41 -->|calls| a830b2dc_75ff_a1e7_d25c_7de2223efe55 098fc190_8120_3755_549b_42f1179f630e["_apply_redact_strategy()"] a830b2dc_75ff_a1e7_d25c_7de2223efe55 -->|calls| 098fc190_8120_3755_549b_42f1179f630e 4c3aef38_195f_f867_1993_4e146c3618c0["_apply_mask_strategy()"] a830b2dc_75ff_a1e7_d25c_7de2223efe55 -->|calls| 4c3aef38_195f_f867_1993_4e146c3618c0 59dbcc65_5bbf_d10e_9919_eaec975a7579["_apply_hash_strategy()"] a830b2dc_75ff_a1e7_d25c_7de2223efe55 -->|calls| 59dbcc65_5bbf_d10e_9919_eaec975a7579 style a830b2dc_75ff_a1e7_d25c_7de2223efe55 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/_redaction.py lines 306–336
def apply_strategy(
content: str,
matches: list[PIIMatch],
strategy: RedactionStrategy,
) -> str:
"""Apply the configured strategy to matches within content.
Args:
content: The content to apply strategy to.
matches: List of detected PII matches.
strategy: The redaction strategy to apply.
Returns:
The content with the strategy applied.
Raises:
PIIDetectionError: If the strategy is `'block'` and matches are found.
ValueError: If the strategy is unknown.
"""
if not matches:
return content
if strategy == "redact":
return _apply_redact_strategy(content, matches)
if strategy == "mask":
return _apply_mask_strategy(content, matches)
if strategy == "hash":
return _apply_hash_strategy(content, matches)
if strategy == "block":
raise PIIDetectionError(matches[0]["type"], matches)
msg = f"Unknown redaction strategy: {strategy}" # type: ignore[unreachable]
raise ValueError(msg)
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does apply_strategy() do?
apply_strategy() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/_redaction.py.
Where is apply_strategy() defined?
apply_strategy() is defined in libs/langchain_v1/langchain/agents/middleware/_redaction.py at line 306.
What does apply_strategy() call?
apply_strategy() calls 3 function(s): _apply_hash_strategy, _apply_mask_strategy, _apply_redact_strategy.
What calls apply_strategy()?
apply_strategy() is called by 1 function(s): apply.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free