Skip to content

fix: preserve negative sign when parsing float fields in TrainingConverter#6546

Open
chuenchen309 wants to merge 1 commit into
crewAIInc:mainfrom
chuenchen309:fix/training-converter-negative-float-regex
Open

fix: preserve negative sign when parsing float fields in TrainingConverter#6546
chuenchen309 wants to merge 1 commit into
crewAIInc:mainfrom
chuenchen309:fix/training-converter-negative-float-regex

Conversation

@chuenchen309

Copy link
Copy Markdown

What

_FLOAT_PATTERN had no -?, so _parse_float('-5.2') returned 5.2 — silently flipping the sign of any negative value parsed during TrainingConverter's field-by-field fallback extraction (used when a smaller LLM's direct-to-Pydantic conversion fails).

This is reachable for any Pydantic model field typed float via _process_field_value -> _parse_float, e.g. text like "-3 degrees" parses to 3.0 instead of -3.0.

Fix

Add the missing -? to the pattern.

How I verified this

  • Added 2 new test cases to test_training_converter.py covering negative-value parsing; confirmed they fail (sign dropped) before the fix, pass after.
  • Ran the full test_training_converter.py suite: 8/8 passed.
  • Ran the broader tests/utilities/ suite: 541 passed.
  • ruff + mypy clean.

Disclosure

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 don't have permission to self-apply GitHub labels (confirmed via gh pr edit --add-label, GraphQL permission error) — disclosing here instead; happy to have a maintainer apply the label if needed.

…erter

_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>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8c4bac88-3ff5-489a-b207-5a00c7c57fff

📥 Commits

Reviewing files that changed from the base of the PR and between 9d72e26 and 4649448.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/utilities/training_converter.py
  • lib/crewai/tests/utilities/test_training_converter.py

📝 Walkthrough

Walkthrough

TrainingConverter now parses negative floating-point values from responses, with unit tests covering conversion and sign preservation.

Changes

Training converter negative values

Layer / File(s) Summary
Negative float parsing and validation
lib/crewai/src/crewai/utilities/training_converter.py, lib/crewai/tests/utilities/test_training_converter.py
The float pattern accepts an optional leading minus sign, and tests verify negative float extraction and conversion.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: preserving negative signs when parsing float fields in TrainingConverter.
Description check ✅ Passed The description directly explains the regex fix, its impact, and the added tests, all of which relate to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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