| def clean_markdown_code(text: str) -> str: | |
| """Removes markdown code blocks from LLM output.""" | |
| lines = text.split("\n") | |
| if not lines: | |
| return text | |
| # Remove starting ```python or similar | |
| if lines[0].strip().startswith("```"): | |
| lines = lines[1:] | |
| # Remove ending ``` | |
| if lines and lines[-1].strip() == "```": | |
| lines = lines[:-1] | |
| return "\n".join(lines).strip() | |