From 808be0185fbc9938e978055cca21784667db7a9d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Feb 2026 08:16:12 +0000 Subject: [PATCH] fix(chat): show only reply text to user, not raw JSON MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The LLM returns a structured JSON object. Previously, raw tokens were streamed directly to the user via msg.stream_token(), causing the full JSON blob to appear in the chat. Fix: collect all chunks silently, parse the JSON, then send only the reply field with cl.Message(content=reply_text).send(). The JSON fields (updates, next_step, registration_complete, language, intent) are still processed in the background — parents never see them. https://claude.ai/code/session_01SUWzMzFvSfWiHXA2p6rPg9 --- chat_app.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/chat_app.py b/chat_app.py index dae5957..cada5c1 100644 --- a/chat_app.py +++ b/chat_app.py @@ -100,17 +100,16 @@ async def on_message(message: cl.Message) -> None: # --- Build system prompt --- system = build_system_prompt(_kb, state) - # --- Stream LLM response --- - msg = cl.Message(content="") + # --- Collect LLM response (JSON), then display only the reply field --- + # The LLM returns a structured JSON object; we must not stream raw tokens + # to the user because they would see the JSON wrapper, not the reply text. full_content = "" try: for chunk in llm.stream_complete(_config.ai_model, system, state.messages): - await msg.stream_token(chunk) full_content += chunk - await msg.send() except Exception: - logger.exception("LLM streaming failed for session %s", state.conversation_id) + logger.exception("LLM call failed for session %s", state.conversation_id) error_text = fallback_message(state.language) await cl.Message(content=error_text).send() # Don't update state — let parent retry @@ -134,6 +133,9 @@ async def on_message(message: cl.Message) -> None: # Append assistant reply to history state.messages.append(ChatMessage(role="assistant", content=reply_text)) + # Send the reply text to the user (parsed from the LLM's JSON response) + await cl.Message(content=reply_text).send() + # --- Handle registration completion --- if is_complete and not state.completed: state.completed = True