fix(retrieval): harden create_chart_tool input validation, numeric coercion, and configurable resilience
GH
5d ago+223+223+012345678901234567890123456789-13-13-01234567890123456789
Failure-Class: none
Summary
Hardens backend/utils/retrieval/tools/chart_tools.py against runtime crashes during chat visualization generation and adds a comprehensive hermetic unit test suite:
-
Defensive Input Validation & Null Guards:
- Guards
labelsandvaluesagainstNoneand non-list types, preventingTypeError: object of type 'NoneType' has no len(). - Requires at least one data point and enforces matching lengths between
labelsandvalues.
- Guards
-
Case-Insensitive Chart Type Normalization:
- Trims and lowercases
chart_type(e.g."Line","BAR"normalize to"line","bar"), avoiding false rejections from slight model casing variations.
- Trims and lowercases
-
Numeric Coercion & Finite Value Validation:
- Coerces string numerals (e.g.
["7.2", "8.0"]or[2024, 2025]) into floats while safely stringifying labels. - Rejects non-numeric,
NaN, andInfvalues cleanly to prevent downstream client-side chart crashes.
- Coerces string numerals (e.g.
-
Configurable Dictionary Resilience:
- Ensures
configurableis safely initialized even whenconfig.get('configurable')returnsNone, eliminatingTypeError: 'NoneType' object does not support item assignment.
- Ensures
-
Hermetic Unit Test Suite:
- Added
backend/tests/unit/test_chart_tools.pywith 10 unit tests (10/10 passing) covering valid line/bar charts, color assignment, casing normalization, invalid chart types, null guards, length mismatches, numeric coercion, invalid/NaN/Inf values, andNoneconfigurable resilience.
- Added
Bounty Proposal ($50 USD)
- Proposed Tier: $50 USD
- Contractor / Settlement: Available for backend & tool engineering contracts (
mahmoudghazy2001@gmail.com).