---
title: "Discussion on \"Sanitize or Fail: Two Ways to Handle Rule Violations in LLM Output\" | Hashnode"
description: "Discussion on \"Sanitize or Fail: Two Ways to Handle Rule Violations in LLM Output\". Split LLM output rule violations into ones your code can repair and ones that must fail the draft, with Python examples and honest limits."
url: "https://hashnode.com/posts/sanitize-or-fail-llm-output-violations/6abd815835485be1d4534c95"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Sanitize or Fail: Two Ways to Handle Rule Violations in LLM Output](https://craigsolomon.hashnode.dev/sanitize-or-fail-llm-output-violations?utm_source=hashnode&utm_medium=feed)

Split LLM output rule violations into ones your code can repair and ones that must fail the draft, with Python examples and honest limits.

Sep 30 · 7 min read · craigsolomon.hashnode.dev  
Read the article

-   [#python](https://hashnode.com/tag/python)
-   [#ai](https://hashnode.com/tag/ai)
-   [#llm](https://hashnode.com/tag/llm)
-   [#automation](https://hashnode.com/tag/automation)
-   [#softwaredevelopment](https://hashnode.com/tag/softwaredevelopment)

## Written by

[Craig Solomon](https://hashnode.com/@craigsolomon)

@craigsolomon · Florida

  
[View profile](https://hashnode.com/@craigsolomon)

Founder, Fulcrum Enterprises — Building the Foundation for an AI Driven Future

Founder, Fulcrum Enterprises. Building the foundation for an AI driven future.

## Responses 1

Markdown supported · ⌘↵ to post

[Mihai\_LeanZero](https://hashnode.com/@mihaileanzero)

[Oct 1](https://hashnode.com/posts/sanitize-or-fail-llm-output-violations/6abd815835485be1d4534c95/comment/6abdf833a2feabd63108b350)

The em dash example draws the line well -- a deterministic string swap doesn't need a model in the loop at all. Where I'd want to know more is the boundary case: a violation that's mechanically detectable (say a banned phrase) but where the fix isn't a safe one-to-one swap, it changes what the sentence actually claims. Does that kind get routed to fail by default, or is there a middle category that still gets a sanitize attempt with a stricter diff check before it's allowed through?
