AI Response Cleaner
A lightweight, zero-dependency Dart package designed to clean raw AI responses (from models like DeepSeek, OpenAI GPTs, Claude, Llama, etc.). It strips out Markdown syntax, HTML tags, thinking blocks, code blocks, and math delimiters to leave you with plain, human-readable text.
Features
- Thinking Tag Removal: Strips out chain-of-thought blocks (
<thinking>,<thought>,<reasoning>). - Markdown Stripping: Removes headers, bold/italic markup, lists, blockquotes, and horizontal rules.
- Code & Link Cleanup: Removes fenced code blocks (```) while preserving standard text, and extracts raw text from links and images.
- Math Delimiters: Cleans up standard LaTeX/MathJax delimiters (
$and$$). - Zero Dependencies: Built entirely using pure Dart regular expressions.
Getting started
Add ai_response_cleaner to your pubspec.yaml:
dependencies:
ai_response_cleaner:
Then run:
dart pub get
or for Flutter
flutter pub get
Usage
import 'package:ai_response_cleaner/ai_response_cleaner.dart';
void main() {
const rawAiResponse = '''
<thinking>
The user is asking for a greeting in bold.
</thinking>
# Hello!
Here is your response in **bold** and *italic*:
Check out [Flutter](https://flutter.dev) for building great apps!
''';
final cleanText = AiResponseCleaner.clean(rawAiResponse);
print(cleanText);
}
Output:
Hello!
Here is your response in bold and italic:
Check out Flutter for building great apps!
Additional information
For more details about AI Response Cleaner, including usage instructions and updates, please visit the MIH Gitea repository.
Contributing
Contributions are welcome! If you'd like to improve the package, please fork the repository, make your changes, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.
Reporting Issues/ Feature Requests
If you encounter any bugs or have feature requests, please log an issue on the MIH Gitea Issues page. Provide as much detail as possible to help us address the problem promptly.
Support and Response
We strive to respond to issues and pull requests in a timely manner. While this package is maintained voluntarily, we appreciate your patience and community involvement.
If you would like to support the MIH development team directly, please feel free to contribute to the MIH Project via DonaHub
Thank you for using the AI Response Cleaner!
Libraries
- ai_response_cleaner
- A utility library for stripping Markdown syntax, HTML tags, thinking blocks, and math delimiters from raw AI responses.