Skip to content

fix: support bare dict as predict output type#2824

Merged
michaeldwan merged 2 commits intomainfrom
md/more-main-fixes
Mar 9, 2026
Merged

fix: support bare dict as predict output type#2824
michaeldwan merged 2 commits intomainfrom
md/more-main-fixes

Conversation

@michaeldwan
Copy link
Member

Summary

  • Fix ValueError: unsupported Cog type Dict when using bare dict as a predict return type
  • Add integration tests covering type gaps found by auditing all supported types against existing test coverage

Bug fix

FieldType.from_type in python/cog/_adt.py did not handle dict-origin types. When a predictor declared -> dict, the legacy Python schema generator converted it to Dict[str, Any], which fell through to the catch-all branch and raised ValueError: unsupported Cog type Dict. The static Go schema generator already handled this correctly via SchemaAnyType().

The fix adds a branch for dict-origin types, mapping them to PrimitiveType.ANY (opaque JSON object {"type": "object"}), consistent with the Go path.

New integration tests

Test Coverage
dict_output -> dict output (the fix)
bool_input_output bool as direct input + output
concatenate_iterator_output ConcatenateIterator[str] output
iterator_string_output Iterator[str] output
list_string_output list[str] output
list_int_input_output list[int] input + output

FieldType.from_type did not handle dict-origin types, causing
'unsupported Cog type Dict' during schema validation. Add a branch
to map dict/Dict[K,V] to PrimitiveType.ANY (opaque JSON object),
matching the static Go schema generator.

Also add integration tests for type coverage gaps: dict output,
bool input/output, ConcatenateIterator[str], Iterator[str],
list[str] output, and list[int] input/output.
@michaeldwan michaeldwan marked this pull request as ready for review March 9, 2026 21:10
@michaeldwan michaeldwan requested a review from a team as a code owner March 9, 2026 21:10
@michaeldwan michaeldwan merged commit a31db53 into main Mar 9, 2026
38 checks passed
@michaeldwan michaeldwan deleted the md/more-main-fixes branch March 9, 2026 22:23
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