Skip to content

Validate Message role field to prevent silent LLM API failures - #41

Merged
claude[bot] merged 1 commit into
mainfrom
improve/20261103-074005
Nov 3, 2026
Merged

claude[bot] merged 1 commit into
mainfrom
improve/20261103-074005

Conversation

@ssevera1

@ssevera1 ssevera1 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

What

Add __post_init__ validation to Message dataclass to reject None or empty role fields.

Why

Message objects with missing or empty roles silently fail at the LLM API layer, making bugs hard to trace. Early validation at construction time catches the issue immediately.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified the diff is a single 4-line __post_init__ on Message that rejects None/empty/whitespace-only roles, matching the PR title and description with no unrelated changes. It follows the same not x or not x.strip() validation pattern already used by add_system/add_user/add_tool_result in the same file, and every internal construction site (add_system, add_user, add_assistant, add_tool_result) passes a hardcoded valid role, so no existing call path regresses; the only other site is load(), where a corrupt saved conversation already raised on a missing role key. No security or error-swallowing concerns — the change surfaces failures earlier rather than hiding them.

@claude
claude Bot merged commit 5a2828c into main Nov 3, 2026
4 checks passed
@claude
claude Bot deleted the improve/20261103-074005 branch November 3, 2026 07:41
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