Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
Filter by Categories
About Article
Analyze Data
Archive
Best Practices
Better Outputs
Blog
Code Optimization
Code Quality
Command Line
Course
Daily tips
Dashboard
Data Analysis & Manipulation
Data Engineer
Data Visualization
DataFrame
Delta Lake
DevOps
DuckDB
Environment Management
Feature Engineer
Git
Jupyter Notebook
LLM
LLM Tools
Machine Learning
Machine Learning & AI
Machine Learning Tools
Manage Data
MLOps
Natural Language Processing
Newsletter Archive
NumPy
Pandas
Polars
PySpark
Python Helpers
Python Tips
Python Utilities
Scrape Data
SQL
Testing
Time Series
Tools
Visualization
Visualization & Reporting
Workflow & Automation
Workflow Automation

Newsletter #259: LangChain v1.0: Auto-Protect Sensitive Data with PIIMiddleware

Newsletter #259: LangChain v1.0: Auto-Protect Sensitive Data with PIIMiddleware


๐Ÿ“… Today’s Picks

LangChain v1.0: Auto-Protect Sensitive Data with PIIMiddleware

Code example: LangChain v1.0: Auto-Protect Sensitive Data with PIIMiddleware

Problem

User messages often contain sensitive information like emails and phone numbers.

Logging or storing this data without protection creates compliance and security risks.

Solution

LangChain v1.0 introduces PIIMiddleware to automatically protect sensitive data before model processing.

PIIMiddleware supports multiple protection modes:

  • 5 built-in detectors (email, credit card, IP, MAC, URL)
  • Custom regex for any PII pattern
  • Replace with [REDACTED], mask as ****1234, or block entirely

Test File Operations Without Risk Using tmp_path

Code example: Test File Operations Without Risk Using tmp_path

Problem

Testing file operations requires touching the actual file system, which can be dangerous if not handled carefully. Real data can be overwritten by mistake.

Tests can also leave behind unwanted files across your project.

Solution

The tmp_path fixture provides a safe alternative by creating temporary, isolated directories that clean up themselves after each test.

Here’s how to use tmp_path:

  • Add tmp_path to your test function signature
  • Work with it like any pathlib.Path object
  • pytest handles the rest: isolated directories per test, automatic cleanup

โ˜•๏ธ Weekly Finds

quarkdown [Python Utils] – Modern Markdown-based typesetting system that compiles projects into print-ready books or interactive presentations with live preview and fast compilation

slim [MLOps] – Container optimization tool that makes Docker images 10-30x smaller without changing your development workflow

shapiq [ML] – Python package for approximating Shapley interactions and explaining feature interactions in machine learning model predictions

Looking for a specific tool? Explore 70+ Python tools โ†’

๐Ÿ“š Latest Deep Dives

Great Tables: Publication-Ready Tables from Polars and Pandas DataFrames – Turn Polars and Pandas DataFrames into professional tables with automatic number formatting, visual heatmaps, and sparkline charts. Fully reproducible when data updates.


Stay Current with CodeCut

Actionable Python tips, curated for busy data pros. Skim in under 2 minutes, three times a week.

Leave a Comment

Your email address will not be published. Required fields are marked *

0
    0
    Your Cart
    Your cart is empty
    Scroll to Top

    Work with Khuyen Tran

    Work with Khuyen Tran