fix: switch structured output to tool-call with reflection retry#879
Merged
fix: switch structured output to tool-call with reflection retry#879
Conversation
Replace the two-pass StructuredOutputWorkflow (TreeSummarize → acomplete) with astructured_predict + reflection retry loop for structured LLM output. - Enable function-calling mode (is_function_calling_model=True) - Use astructured_predict with PromptTemplate for first attempt - On ValidationError/parse failure, retry with reflection feedback - Add min_length=10 to TopicResponse title/summary fields - Remove dead StructuredOutputWorkflow class and its event types - Rewrite tests to match new astructured_predict approach
The switch to astructured_predict dropped the texts parameter entirely, causing summary prompts (participants, subjects, action items) to be sent without the transcript content. Combine texts with the prompt before calling astructured_predict, mirroring what TreeSummarize did.
yamijuan
approved these changes
Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The two-pass structured output approach (TreeSummarize → JSON formatting via acomplete) had a 25% success rate with Kimi K2.5. The model would produce valid text analysis but fail to format it as valid JSON consistently, causing topic detection and summarization failures in production.
Solution
Replaced
StructuredOutputWorkflowwithastructured_predict(tool-call / function-calling mode) + reflection retry loop:astructured_predictuses the LLM's native tool-call interface to produce structured output directly as a Pydantic object, bypassing the fragile two-pass text→JSON pipelineValidationErroror parse failure, the error is fed back to the LLM as a reflection prompt and the call is retried (up toLLM_PARSE_MAX_RETRIES)min_length=10onTopicResponse.titleandTopicResponse.summaryfields catches short/empty content via Pydantic validation, triggering reflection retryBenchmark results
Changes
server/reflector/llm.py—is_function_calling_model=True, rewroteget_structured_response(), removed deadStructuredOutputWorkflowclass + event typesserver/tests/test_llm_retry.py— rewrote tests for the newastructured_predictapproach (9 tests, all passing)Full analysis
Structured output benchmark analysis
Test plan
uv run pytest tests/test_llm_retry.py -v— 9/9 passuv run pytest— full suite passes (failures are pre-existing Redis/infra issues)debug_topic.py— 10/10 successdebug_topic.py— 7/7 success (3 timed out on local Ollama)