Skip to content

Detect pydantic.BaseModel in output types and error with migration guidance #2922

Description

@michaeldwan

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions