Skip to content

feat: add Pydantic response models for all endpoints #41

Description

@gordonmurray

Right now all six endpoints return plain dict / JSONResponse objects constructed by hand in app.py. FastAPI can infer loose schemas from the return type hints but there is no enforced contract between the backend and the frontend, and the OpenAPI schema that FastAPI generates is correspondingly thin.

Adding Pydantic response models would:

  • Give the frontend a stable contract to rely on. Serialization drift between backend versions would fail in the route handler rather than silently returning a malformed shape to the UI.
  • Produce a much richer OpenAPI schema. This pairs naturally with feat: expose FastAPI /docs endpoint for API discovery #23, which covers exposing the Swagger UI at /docs.
  • Catch bugs at the boundary. If serialize_arrow_value returns something that does not match the declared shape, Pydantic raises a clear validation error instead of the frontend getting mystery fields.

No new dependencies: Pydantic is already a transitive dependency of FastAPI.

Sketch:

from pydantic import BaseModel

class HealthResponse(BaseModel):
    ok: bool
    app_version: str
    lancedb_version: str
    pyarrow_version: str
    build_tag: str | None = None
    compat: dict[str, bool]

@app.get("/healthz", response_model=HealthResponse)
async def healthz() -> HealthResponse:
    ...

Scope: one model per endpoint (six total), plus the nested shapes for /schema, /columns, and the vector cell object. Can be done in a single PR without touching any business logic, just the return types and response construction.

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions