Drupal is a registered trademark of Dries Buytaert
Views Bootstrap 5.5.2 Minor update available for module views_bootstrap (5.5.2). oEmbed Providers 3.0.0 Major update available for module oembed_providers (3.0.0). Byte (theme) 1.0.3 Minor update available for theme byte_theme (1.0.3). Token Content Access 3.1.3 Minor update available for module tca (3.1.3). Emulsify 7.2.1 Minor update available for theme emulsify (7.2.1). Opensolr Search 4.1.0 Minor update available for module opensolr_search (4.1.0). AG-UI 1.0.2 Minor update available for module agui (1.0.2). FileGate 1.5.0 Minor update available for module file_gate (1.5.0). oEmbed Providers 2.2.4 Module oembed_providers updated after 7 months of inactivity (2.2.4). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module offers a text filter and a Drush command to clean up formatting issues common in AI-generated text. It can remove extra characters, normalize spacing and punctuation, and strip markdown elements, either automatically when content is saved or in bulk via Drush.

AI Text Cleaner

AI Text Cleaner is a small Drupal module that provides a text filter and a Drush command to clean formatting quirks from ChatGPT or other LLM outputs.
It removes hidden or problematic characters, converts non-breaking spaces, normalizes dashes and quotes, converts ellipses, and strips Markdown-style headings and stray asterisks.

Features

  • Text filter plugin that can be enabled on input formats to clean content on save.
  • Options supported:
    • Remove hidden/control characters
    • Convert non-breaking spaces to regular spaces
    • Normalize dashes (hyphen/en dash/em dash) to a standard hyphen
    • Normalize quotes (curly “smart” quotes → straight quotes)
    • Convert ellipses (…) to three periods (...)
    • Remove trailing whitespace
    • Remove stray asterisks and stray list artifacts
    • Strip Markdown-style headings (leading # characters)
  • Drush command ai:text-clean (alias ai-text-clean) to run the cleaner across nodes in bulk.
  • Per-option statistics exported for reporting or CSV-like table output.
  • Analysis mode (dry run) that reports what would change without saving.
  • Ability to limit by content type (bundle), language, and maximum node count.

Dependencies

  • Drupal core (module developed for Drupal 11)
  • PHP 8.1 or newer
  • Optional: Drush (to use the ai:text-clean command)
  • Filter system: integrates with Drupal's core filter subsystem (ensure input formats are configured).

Installation

  1. Place the module in web/modules/custom/ai_text_cleaner.
  2. Enable the module (example using Drush):
drush en ai_text_cleaner -y

To automatically apply the filter, go to Configuration → Text formats and editors, edit the target input format, and enable the "AI Text Cleaner" filter at the desired weight.

Plain-text field cleaning (since v1.1)

A new configuration option allows the module to clean simple text fields (fields without an assigned Text Format) when content is saved. To enable and configure this:

  1. Go to Administration → Configuration → Content → AI Text Cleaner settings (or visit /admin/config/content/ai-text-cleaner).
  2. Enable "Clean plain text fields" and choose which cleaning options to apply to plain text fields.

When enabled, the same cleaning rules that the filter uses for formatted text (remove hidden characters, normalize dashes/quotes/guillemets, convert ellipses, etc.) will be applied to fields that don't have a text format set.

Usage with Drush

Analyze (dry run) all nodes of type article:

drush ai:text-clean --types=article --analysis=TRUE

Apply cleaning and save changes for up to 50 nodes across all languages:

drush ai:text-clean --limit=50 --analysis=FALSE

You can supply multiple content types or languages as comma-separated lists, for example --types=article,page or --languages=en,de.

Activity

Total releases
4
First release
Mar 2026
Latest release
3 months ago
Releases (12 mo)
4 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Release date
1.1.0 Stable Apr 4, 2026
1.1.0-rc1 Pre-release Apr 2, 2026
1.0.1 Stable Mar 14, 2026
1.0.0 Stable Mar 14, 2026