fix: add dataclass-aware YAML field type validation at parse time#192
Merged
Conversation
YAML values with unquoted colons silently parse as dicts instead of strings, causing opaque TypeError from protobuf C code at push time. Uses dataclasses.fields() + typing.get_type_hints() to automatically validate str and list[str] fields in YamlResource.read_local_resource, with recursion into nested dataclass fields. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
A list[str] field receiving a dict (e.g., prompt_assertions parsed as a mapping) would iterate dict keys as strings, silently passing the check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
- Check all scalar types (str, int, float, bool) not just str - Validate dict[K, V] keys and values when K/V are scalar types - Accept int where float is expected (YAML parses 500 as int) - Reject bool where int/float is expected (yes/no auto-cast) - Validate list[str] field is actually a list, not a dict - Remove verbose YAML hint from error messages Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This comment has been minimized.
This comment has been minimized.
Contributor
Coverage Report
Changed file coverage
|
oeisenberg
approved these changes
Jun 17, 2026
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.
Summary
Adds automatic type validation for YAML resource fields at parse time, catching the colon-space footgun where unquoted strings silently parse as dicts.
Motivation
YAML values with unquoted mid-sentence colons (e.g.,
the outcome: either a time slot or...) silently parse as dicts instead of strings. This causes opaqueTypeError: bad argument type for built-in operationfrom protobuf C code at push time — with no hint about which field or file caused it. A confirmed case inprompt_assertionsburned ~7 push attempts before the user found the cause.Supersedes #191 — moves the detection from
project.py's generic error handler down to the YAML resource layer with field-level precision.Changes
check_yaml_field_types()inresource.pyusingdataclasses.fields()+typing.get_type_hints()to introspect declared types and validatestr/list[str]fields aren't dictsTestCaseAssertion.promptsinsideTestCase)YamlResource.read_local_resource— all YAML resources get the check automaticallyFlowStepandPronunciationoverridingread_local_resourcemethodsTest strategy
poly <command>)Checklist
ruff check .andruff format --check .passpytestpassespolyCLI interface (or migration path documented)Screenshots / Logs
Example error output for the confirmed bug (test case with unquoted colon in prompt assertion):
🤖 Generated with Claude Code