r/Python • u/Academic_Break4234 • Mar 09 '26
News llmclean — a zero-dependency Python library for cleaning raw LLM output
Built a small utility library that solves three annoying LLM output problems I have encountered regularly. So instead of defining new cleaning functions each time, here is a standardized libarary handling the generic cases.
strip_fences()— removes the\``json ```` wrappers models love to addenforce_json()— extracts valid JSON even when the model returnsTrueinstead oftrue, trailing commas, unquoted keys, or buries the JSON in prosetrim_repetition()— removes repeated sentences/paragraphs when a model loops
Pure stdlib, zero dependencies, never throws — if cleaning fails you get the original back.
pip install llmclean
GitHub: https://github.com/Tushar-9802/llmclean
PyPI: https://pypi.org/project/llmclean/
7
u/latkde Tuple unpacking gone wrong Mar 09 '26
This is AI slop. The first commit was made less than 1h ago. No one should use such an immature project.
This is unnecessary. Most inference services now offer structured output features such as a JSON mode where sampling is constrained so that the model is unable to generate tokens other than syntactically valid JSON.
I've written this kind of fixup code myself, but I recently got to delete all of it because it's simply no longer necessary since early 2025.