fix: clamp dispatcher confidence score to valid range [0.0, 1.0]#45
Open
stuagano wants to merge 1 commit intodatabrickslabs:feature/flowfrom
Open
fix: clamp dispatcher confidence score to valid range [0.0, 1.0]#45stuagano wants to merge 1 commit intodatabrickslabs:feature/flowfrom
stuagano wants to merge 1 commit intodatabrickslabs:feature/flowfrom
Conversation
LLMs occasionally return confidence scores > 1.0 (e.g., 1.2) when highly
confident in their intent classification. This causes Pydantic validation
errors since the DispatcherResponse schema constrains confidence to [0, 1].
This fix clamps the confidence value to the valid range before creating
the DispatcherResponse object, preventing validation errors while preserving
the intent that the model was highly confident.
Error observed:
pydantic_core._pydantic_core.ValidationError: 1 validation error for DispatcherResponse
confidence
Input should be less than or equal to 1 [type=less_than_equal, input_value=1.2, input_type=float]
Changes:
- Added confidence clamping: min(max(float(confidence), 0.0), 1.0)
- Added explanatory comment about LLM behavior
Fixes dispatcher crashes during chat intent detection.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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
LLMs occasionally return confidence scores > 1.0 (e.g., 1.2) when highly confident in their intent classification. This causes Pydantic validation errors since the
DispatcherResponseschema constrains confidence to[0, 1].Error observed:
This error crashes the dispatcher service during chat intent detection, preventing users from interacting with the chat interface.
Solution
Clamp the confidence value to the valid range
[0.0, 1.0]before creating theDispatcherResponseobject:This fix:
Changes
dispatcher_service.pyline 948Testing
Impact
Fixes dispatcher crashes during chat intent detection.