Skip to content

[codex] sanitize hidden reasoning from LLM outputs - #716

Draft
aimdotsh wants to merge 1 commit into
pingcap:mainfrom
aimdotsh:codex/sanitize-hidden-reasoning
Draft

[codex] sanitize hidden reasoning from LLM outputs#716
aimdotsh wants to merge 1 commit into
pingcap:mainfrom
aimdotsh:codex/sanitize-hidden-reasoning

Conversation

@aimdotsh

@aimdotsh aimdotsh commented Jul 6, 2026

Copy link
Copy Markdown

Summary

  • Strip hidden reasoning blocks such as <think>...</think> from rewritten questions and final chat answers.
  • Preserve streaming answer delivery while filtering hidden reasoning chunks.
  • Parse recommended questions into clean question lines and retry when malformed output yields too few questions.
  • Add unit tests for reasoning-tag stripping, split streaming tags, and recommended-question parsing.

Root cause

Some LLM providers can emit hidden reasoning or formatter text despite prompt instructions. AutoFlow previously trusted these responses and stored or displayed them directly, so malformed model output could leak into chat answers, retrieval queries, and recommended questions.

Validation

  • python3 -m py_compile backend/app/rag/utils.py backend/app/rag/chat/chat_flow.py backend/app/rag/chat/chat_service.py backend/tests/test_rag_utils.py
  • uv run pytest -q tests/test_rag_utils.py
  • uv run ruff check app/rag/utils.py app/rag/chat/chat_flow.py app/rag/chat/chat_service.py tests/test_rag_utils.py

@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

@aimdotsh is attempting to deploy a commit to the pingcap Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant