Python Filename Sanitization with Fallback

Sanitizes document titles into filesystem-compatible filenames with metadata fallback.

Updated Jan 23, 2026
One-click install
npx skills add https://github.com/ngpestelos/readwise-mcp-server --skill python-filename-sanitization-with-fallback
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Python Filename Sanitization with Fallback
Source: https://github.com/ngpestelos/readwise-mcp-server/tree/main/.claude/skills/python-filename-sanitization-fallback
Command: npx skills add https://github.com/ngpestelos/readwise-mcp-server --skill python-filename-sanitization-with-fallback

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill tackles the challenge of generating safe, filesystem-compatible filenames from user-provided titles, especially when titles contain emoji, punctuation, or whitespace. It adds a metadata-driven fallback to guarantee filenames always include alphanumeric content and remain descriptive for indexing.

Core Features & Use Cases

  • Sanitizes titles to remove invalid characters while preserving meaning where possible.
  • Validates output to ensure the resulting filename contains alphanumeric characters.
  • Metadata-driven fallback leverages author, date, and category to craft descriptive, unique names when sanitization would produce invalid results.
  • Deterministic & backward-compatible: same input and metadata produce the same output; existing valid filenames are unchanged.

Quick Start

Use the sanitize_filename function to convert a document title into a safe filename, providing optional metadata for fallback. Command example: sanitize_filename("…", {"author": "User", "saved_at": "2025-12-08", "category": "tweet"})

Frequently Asked Questions about Python Filename Sanitization with Fallback

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I sanitize a filename to remove emoji and punctuation?

To sanitize a filename, this skill removes invalid characters like emoji and punctuation while preserving the original meaning. It validates the output to ensure the resulting filename always contains alphanumeric characters for safe filesystem indexing.

What happens when filename sanitization leaves no valid characters?

When sanitization leaves no valid characters, a metadata-driven fallback generates a descriptive name. It uses provided metadata like author, date, and category to ensure the filename remains unique and valid for document indexing.

How do I generate deterministic filenames from document titles?

Generating deterministic filenames ensures the same input title and metadata always produce the same output filename. This approach maintains backward compatibility by leaving existing valid filenames unchanged during the import process.

Can I use document metadata as a fallback for empty filenames?

Yes, you can pass a metadata dictionary containing author, saved_at, and category details. If the title consists entirely of special characters, this metadata is used to construct a unique, descriptive fallback filename.

Are there limitations to filename sanitization with special characters?

A limitation of filename sanitization is that titles consisting solely of whitespace or special characters cannot retain their original meaning. The skill must rely entirely on metadata or timestamp-based fallbacks to generate a valid name.

Related Skills