Skip to content

Commit 7a73959

Browse files
chuenchen309claude
andcommitted
fix: preserve negative sign when parsing float fields in TrainingConverter
_FLOAT_PATTERN had no `-?`, so _parse_float('-5.2') returned 5.2 and "-3 degrees" parsed as 3.0 -- silently flipping the sign of any negative value during TrainingConverter's field-by-field fallback extraction (used when a smaller LLM's direct-to-Pydantic conversion fails). Reachable for any Pydantic model field typed `float` via _process_field_value -> _parse_float. Add the missing `-?` to the pattern. AI-Generated PR: Yes, drafted with Claude Code and personally reviewed/tested before submission. Per CONTRIBUTING.md's llm-generated label requirement: as an external contributor I cannot self-apply GitHub labels (confirmed via `gh pr edit --add-label`, GraphQL permission error) -- disclosing here in the PR body/commit instead; happy to have a maintainer apply the label if needed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 0e5d0ec commit 7a73959

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/crewai/src/crewai/utilities/training_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from crewai.utilities.converter import Converter, ConverterError
88

99

10-
_FLOAT_PATTERN: Final[re.Pattern[str]] = re.compile(r"(\d+(?:\.\d+)?)")
10+
_FLOAT_PATTERN: Final[re.Pattern[str]] = re.compile(r"(-?\d+(?:\.\d+)?)")
1111

1212

1313
class TrainingConverter(Converter):

lib/crewai/tests/utilities/test_training_converter.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,12 @@ def test_process_field_value_float(self):
9595
response = "The quality score is 8.5 out of 10"
9696
result = self.converter._process_field_value(response, float)
9797
assert result == 8.5
98+
99+
def test_process_field_value_float_negative(self):
100+
response = "The temperature delta is -3.2 degrees"
101+
result = self.converter._process_field_value(response, float)
102+
assert result == -3.2
103+
104+
def test_parse_float_preserves_negative_sign(self):
105+
assert TrainingConverter._parse_float("-5.2") == -5.2
106+
assert TrainingConverter._parse_float("-3 degrees") == -3.0

0 commit comments

Comments
 (0)