Repository navigation
Closed
Feature
Copy link
Labels
enhancementNew feature or request
Description
What feature would you like to be added?
ModelOutputThunk.parsed_repr is None before a thunk is computed, and also when a component's _parse legitimately returns None. Code can't tell the two apart, so core enforces "a computed thunk has a non-None parsed_repr" with an assert. That assert is wrong for any component whose output type includes None.
Proposal: Track whether parsing happened separately from what it
- Add a parsed flag (e.g. _parsed: bool) or a sentinel (_UNPARSED = object()) to ModelOutputThunk. Set it in _set_parsed_repr() and anywhere else parsed_repr is assigned.
- Change the invariant to "a computed thunk has been parsed", and drop the GenerativeStub exemption and its import.
- Have consumers ask "was this parsed?" rather than "omponent that parsed to None would then render
consistently, either as its parsed value via str() - Update the parsed_repr docstring.
Why is this feature needed?
Currently
- parsed_repr: S | None is documented as "Will be non-None once computed" (mellea/core/base.py:1184).
- After _set_parsed_repr(), ModelOutputThunk asserts that parsed_repr is non-None, unless the action is a GenerativeStub (mellea/core/base.py:1570-1581). The exemption has to import GenerativeStub lazily from stdlib to avoid a circular import.
- Two consumers read parsed_repr is None as "there's no parsed form, use the raw value":
- mellea/formatters/chat_formatter.py:78 builds a message from c.value when parsed_repr is None.
- mellea/stdlib/components/chat.py:462 does the same, and raises if value is also None.
Why it matters
- Any component outside stdlib whose type parameter allows None hits the assert and can't opt out.
- Core depends on stdlib for a policy decision, not fo Message re-parse at base.py:1707).
- The only thing stopping a non-nullable stub from silat its pydantic response model rejects null. That's
pinned by test_non_nullable_stub_rejects_null_result
Any alternative solution that you may want to share?
No response
Anything else we need to know?
Places to update
- Assignments to parsed_repr, which must also set the- mellea/core/base.py: _set_parsed_repr (1688, 1707)py at 1787/1789- the five backends' generate_from_raw: ollama.py:13m.py:838, watsonx.py:803, huggingface.py:2773- sampling strategies that re-parse: stdlib/samplingng.py:211
- Reads of parsed_repr is None: formatters/chat_formatter.py:78, stdlib/components/chat.py:462
- ComputedModelOutputThunk: it leaves parsed_repr unguarded on purpose because sampling strategies finalize it later, so check whether the flag should get the same treatment. Tests: test/core/test_component_typing.py:178,182 asne and would move to the new check.sentinel avoids a second field and makes "unparsed" a real value. But parsed_repr is public, so a sentinelvisible through it would be a breaking change. A private flag with parsed_repr still typed S | None is the backward-compatible option.
Acceptance criteria
- No stdlib class is named in ModelOutputThunk's invarA component of any origin whose _parse returns NoneA component that doesn't override _parse, or whose ps loudly.
- Chat formatting renders a thunk that parsed to None by one documented rule.
- Existing stub tests pass, including test_sync_stub_returns_none_result, test_async_stub_returns_none_result, test_non_nullable_stub_rejects_null_result and test__to_none_still_fails. The last one changes meaning: itshould test "parse never ran", not "parsed to None".
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity