Skip to content

fix: validate Message objects in validate_messages#55

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/justllms-repository-improvements-96bf
Draft

fix: validate Message objects in validate_messages#55
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/justllms-repository-improvements-96bf

Conversation

@cursor

@cursor cursor Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a validation inconsistency where pre-built Message objects bypassed all checks in validate_messages(), while equivalent dict inputs were fully validated.

Branch: darshan/validate-message-objects

Problem

When callers passed Message instances directly, they were appended without validation. This allowed invalid messages (e.g. empty user content) to reach provider APIs, while the same content as a dict would raise ValidationError.

Solution

Convert Message objects to dicts via model_dump() and route them through the existing dict validation path, ensuring consistent behavior regardless of input type.

Tests

Added tests/test_validators.py covering:

  • Empty and whitespace-only user content rejection for Message objects
  • Tool role messages with empty content (allowed)
  • Assistant messages with tool_calls and empty content (allowed)
  • Mixed dict/Message input

CI

All checks pass locally:

  • ruff check justllms/
  • black --check justllms/
  • mypy justllms/ --ignore-missing-imports
  • pytest tests/ -v (102 tests)
  • python3 -m build
Open in Web View Automation 

Message instances were previously appended without running the same
checks applied to dict inputs, allowing empty user content to slip
through when callers passed pre-built Message objects.

Convert Message objects via model_dump() and route them through the
existing dict validation path. Add tests covering empty content,
tool turns, and mixed dict/Message input.

Co-authored-by: Darshan Harihar <DarshanHarihar1@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant