"""Text cleaning and chunking utilities for LLM payloads. Provides aggressive HTML-stripping, whitespace normalisation, and intelligent splitting of long text into sequential chunks that avoid cutting mid-sentence when possible. """ import re from typing import List from bs4 import BeautifulSoup def clean_text_for_llm(html_content: str) -> str: """Strip HTML, collapse whitespace, and remove non-ASCII for LLM input. Removes ````, ````, ``