Skip to content

Python: [Bug]: load_settings silently accepts invalid values for non-Optional union fields #8907

Description

Description

_coerce_value (agent_framework/_settings.py) only runs its per-arm union coercion when None is one of the arms. For any other union, e.g. int | float, it falls through to return value. The raw string is returned unchanged, and invalid input is accepted without error.

This contradicts the documented contract in packages/core/AGENTS.md: "Invalid supplied numeric and boolean environment or .env values raise ValueError identifying the field and source".

Suggested fix: handle any Union / types.UnionType origin with the same try-each-arm loop, treating the None arm as optional, and raise when no arm matches.

Code Sample

from agent_framework._settings import _coerce_value

_coerce_value("5", int | None)    # 5      (correct)
_coerce_value("5", int | float)   # '5'    (str, expected 5)
_coerce_value("abc", int | float) # 'abc'  (expected ValueError)

Error Messages / Stack Traces

Package Versions

agent-framework-core 1.19.0 (main @ 853c456)

Python Version

Python 3.11

Additional Context

Found during a code review of main @ 853c456 (2026-09-30); the repro above was run against that commit.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions