Skip to content

Validate Observation representation invariant at construction time #108

Description

@Andrew9603

Summary

Observation documents that exactly one of text, messages, or token_ids should be set, but this invariant is currently not validated at construction time.

Consequently:

  • Observation() fails only later during prompt conversion.
  • An observation containing multiple representations is silently accepted, with _obs_to_prompt() selecting one according to its branch order.

Proposed change

Add a lightweight __post_init__() validation to Observation that raises ValueError unless exactly one representation is non-None.

The validation would use is not None, so intentionally empty representations such as Observation(messages=[]) remain valid.

I would also add CPU-only unit tests covering:

  • Each valid representation
  • Empty strings and empty lists
  • No representation
  • Conflicting combinations of multiple representations

This change would apply only to Observation. Action would remain unchanged because the rollout loop intentionally constructs it with both decoded text and token IDs.

Would this validation align with the intended API contract? I’d be happy to submit a PR if so.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions