When a predictor returns a pydantic.BaseModel subclass, cog push fails with a raw PydanticSchemaGenerationError traceback about cog.types.Path. The error message suggests arbitrary_types_allowed=True -- which is a Pydantic-specific workaround, not the right fix. There's no indication that cog.BaseModel exists or that it replaced pydantic.BaseModel for structured outputs in 0.17.
# User has this, gets an opaque Pydantic error on push
from pydantic import BaseModel
from cog import Path
class Output(BaseModel):
file: Path # PydanticSchemaGenerationError
The schema generation step (cog.command.openapi_schema) already introspects predict method return types. If the return type is a pydantic.BaseModel subclass rather than cog.BaseModel, it could catch this early and error with guidance:
Output inherits from pydantic.BaseModel.
Cog 0.17+ uses cog.BaseModel for structured outputs.
Change: from cog import BaseModel
The check is straightforward -- issubclass(return_type, pydantic.BaseModel) guarded by a try/import since pydantic is now optional. This turns an opaque traceback into a one-line actionable fix.
Related to #2919 (the other 0.17 compat issue from the same deploy).
When a predictor returns a
pydantic.BaseModelsubclass,cog pushfails with a rawPydanticSchemaGenerationErrortraceback aboutcog.types.Path. The error message suggestsarbitrary_types_allowed=True-- which is a Pydantic-specific workaround, not the right fix. There's no indication thatcog.BaseModelexists or that it replacedpydantic.BaseModelfor structured outputs in 0.17.The schema generation step (
cog.command.openapi_schema) already introspects predict method return types. If the return type is apydantic.BaseModelsubclass rather thancog.BaseModel, it could catch this early and error with guidance:The check is straightforward --
issubclass(return_type, pydantic.BaseModel)guarded by a try/import since pydantic is now optional. This turns an opaque traceback into a one-line actionable fix.Related to #2919 (the other 0.17 compat issue from the same deploy).