Skip to content

Migration 0.37x

Use when upgrading from a version older than these releases: 0.374.0, 0.373.0 and 0.372.0.

Part of the Migration guide.

0.374.0 — Agent and AIChatPipeline run tool calls written in the text

A model reply with empty tool_calls used to always be the final answer, even when content was exactly a JSON call ({"name": "buscar_pedido", "arguments": {"pedido_id": "PED-1042"}}). Now, by default, the Agent and the AIChatPipeline tool loop run that call when the whole text is call JSON and every name is a registered tool (#866). The tool step carries AgentStep.from_text=True.

What can change for you: an agent whose legitimate answer is a JSON object with a tool's name and an arguments key now runs that tool instead of returning the JSON. To keep the old behaviour:

from tempest_fastapi_sdk.agents import Agent
from tempest_fastapi_sdk.genai import AIChatPipeline, OllamaGenerator

generator = OllamaGenerator("qwen2.5-coder:14b")
agent = Agent(generator, parse_text_tool_calls=False)
pipeline = AIChatPipeline(generator, parse_text_tool_calls=False)

0.374.0 — strict schema in structured output and truncated images refused

Where What changes What to do
OllamaGenerator.chat_structured / generate_structured The schema sent as format has every field in required (defaulted ones and X \| None too, which still accept null). The model now emits fields it used to omit — and that the default silently filled: on gpt-oss:20b per-field accuracy went from 70.8 to 95.4 (33 cases, 2026-11-26/27, Ollama 0.30.11) Nothing, in most cases. If a defaulted field meant "the model need not fill this", the model now fills it: check defaulted fields your code reads as a sign of absence
make_vision_router with max_image_pixels (default), FaceRecognizer, genai image loading and share A truncated image is refused even after weasyprint (the [pdf] extra) was imported in the process; before, it passed. The router answers 422 without calling the model, at the cost of one more decode (~70 ms on a 12 MP JPEG, measured). FaceRecognizer and genai decode the image right away: the exception surfaces at the call, and an image passed by path is read into memory A client that sent a truncated image now gets 422. With max_image_pixels=None the router check stays off

0.373.0 — BaseController and BaseService bind ResponseT to the layer below

Previously, BaseController declared its own ResponseT independently of the service and reached it via cast("ResponseT", ...) — a controller repeating the wrong schema passed mypy --strict and returned the service's schema at runtime (#838):

from typing import Any
from uuid import UUID

from tempest_fastapi_sdk import BaseController, BaseSchema, BaseService


class UserResponseSchema(BaseSchema):
    email: str


class OrderResponseSchema(BaseSchema):
    total: int


class UserService(BaseService[Any, UserResponseSchema]):
    pass


class WrongController(BaseController[UserService, OrderResponseSchema]):
    pass


async def total(controller: WrongController, id: UUID) -> int:
    return (await controller.get_by_id(id)).total  # docs-guard: skip

BaseController's get_by_id, list and update now derive the response type (and, for update, the update schema) directly from ServiceT. On the snippet above, mypy --strict now fails with "UserResponseSchema" has no attribute "total" [attr-defined] and basedpyright with Cannot access attribute "total" for class "UserResponseSchema".

Existing BaseController[Service, Resp], BaseController[Service, Resp, Update] and BaseRepository[Model] declarations stay accepted for compatibility whenever they agree with the service. The recommended form is shorter and also ties the repository:

from sqlalchemy import String
from sqlalchemy.orm import Mapped, mapped_column

from tempest_fastapi_sdk import (
    BaseController,
    BaseModel,
    BaseRepository,
    BaseResponseSchema,
    BaseSchema,
    BaseService,
)


class UserModel(BaseModel):
    __tablename__ = "migration_users_example"

    email: Mapped[str] = mapped_column(String(64), nullable=False)


class UserResponseSchema(BaseResponseSchema):
    email: str


class UserUpdateSchema(BaseSchema):
    email: str | None = None


class UserRepository(BaseRepository[UserModel, UserResponseSchema]):
    def map_to_response(self, instance: UserModel) -> UserResponseSchema:
        return UserResponseSchema.model_validate(instance)


class UserService(
    BaseService[UserRepository, UserResponseSchema, UserUpdateSchema]
):
    pass


class UserController(BaseController[UserService]):
    pass

If one of your controllers fails after upgrading:

  • Controller declared the wrong response schema: fix the service or write BaseController[YourService] so both response and update schemas come straight from the service.
  • Two-argument controller over a three-argument service calling update: controller.update(id, payload) now requires the service's UpdateT instead of any BaseSchema; pass the concrete update schema.
  • Service whose BaseRepository[Model, Resp] disagrees with the service's ResponseT: basedpyright now rejects the call site until both declare the same response schema.

0.373.0 — ObjectStat.raw can be None

ObjectStat.raw is now annotated minio.datatypes.Object | None (#836). Nothing changes at runtime: AsyncMinIOClient still fills in the minio Object, and LocalObjectStorageClient and FakeObjectStorageClient still return None, as they always did. What changes is the checker: an unchecked read such as stat.raw.version_id is now error: Item "None" of "Object | None" has no attribute "version_id" [union-attr] under mypy. Before, it accepted the line, which raised AttributeError against the local backend and the fake.

Narrow before reading:

from tempest_fastapi_sdk.storage import ObjectStat


def version_of(stat: ObjectStat) -> str | None:
    if stat.raw is None:
        return None
    return stat.raw.version_id

If you already had that check and silenced mypy's unreachable (warn_unreachable) with # type: ignore, the ignore is no longer needed.

0.373.0 — SignedCookieSessionStore's same_site typed as a Literal

SignedCookieSessionStore's same_site parameter was a str and is now SameSite (Literal["lax", "strict", "none"], exported from tempest_fastapi_sdk). A value outside the three now raises ValueError at construction, instead of an AssertionError on the first login. mypy rejects (arg-type) two forms that used to pass:

  • A str variable: annotate it as SameSite, or read the value from a settings field already typed that way (SessionSettings.SESSION_COOKIE_SAMESITE is SessionCookieSameSite, the same Literal).
  • A capitalized spelling ("Lax", "Strict"): write it lower-case. At runtime it is still accepted and stored lower-cased, so the Set-Cookie header goes from SameSite=Strict to SameSite=strict.
from tempest_fastapi_sdk import SameSite
from tempest_fastapi_sdk.admin import SignedCookieSessionStore

policy: SameSite = "strict"
store: SignedCookieSessionStore = SignedCookieSessionStore(
    "change-me-to-a-32-byte-secret-key!!",
    same_site=policy,
)

0.373.0 — BaseUserModel without phantom columns

BaseUserModel declared totp_secret, totp_enabled_at, totp_last_step and name for the type checker only. At runtime those columns come from MFAMixin and NameMixin, so a model without the mixin passed mypy --strict and raised AttributeError on the line:

from tempest_fastapi_sdk import BaseUserModel


class UserModel(BaseUserModel):
    __tablename__ = "users"


def label(user: UserModel) -> str:
    return user.name  # docs-guard: skip

mypy --strict now refuses that line with "UserModel" has no attribute "name" [attr-defined]. The code already broke at runtime; the change only moves the error to the checker. Pick one of two ways out:

  • The model has the column: inherit the mixin (class UserModel(NameMixin, BaseUserModel), or MFAMixin for the totp_* columns) and generate the migration.
  • The function accepts any BaseUserModel: narrow before reading.
from datetime import datetime

from tempest_fastapi_sdk import BaseUserModel, MFAMixin, NameMixin


def display(user: BaseUserModel) -> str:
    if isinstance(user, NameMixin):
        return user.name
    return user.email


def enabled_at(user: BaseUserModel) -> datetime | None:
    if isinstance(user, MFAMixin):
        return user.totp_enabled_at
    return None

The SDK now reads the columns the same way, which changes three behaviours for a model without the mixin:

  • UserAuthService.mfa_enroll raises TypeError before writing any row. It used to return a secret with no column to live in and store the recovery codes. mfa_confirm answers 422 (MFA not initialized), and mfa_disable / mfa_reset, which raised AttributeError, answer 422 (MFA not active).
  • A model that declares its own name column, without NameMixin, registers the passkey (WebAuthnService.register_begin) with the e-mail as display_name. To keep the name, replace the hand-written column with NameMixin.
  • tempest user create --require-mfa and tempest user mfa-reset require MFAMixin on the class; hand-declared totp_* columns are no longer enough.

0.373.0 — runtime breaks outside the checker and narrowed public types

Three changes in this release break at runtime, not only in the type checker:

Where What changes What to do
recall_prompt(memory, ...) Calls memory.search(user_id=..., query=..., top_k=...) — the method ChatMemory and PgChatMemory have — instead of memory.recall(...), which no SDK class had. A custom memory that only implemented recall now raises AttributeError (it used to return "" silently); a failing backend that has search still returns "", with a WARNING on the tempest_fastapi_sdk.agents.memory logger Implement search(*, user_id, query, top_k) returning the MemoryHits, or pass a ChatMemory/PgChatMemory. The SupportsMemorySearch Protocol describes the shape
Agent and AIChatPipeline with tools Decide through isinstance(generator, ToolCallingBackend), which requires chat and chat_with_tools. A test double with only chat_with_tools stops running the tool loop Give the double async def chat(self, messages, /) -> str too
FakePixProvider.parse_webhook(event) Takes object and raises TypeError (parse_webhook expects a mapping, got str.) for anything that is not a Mapping Pass the webhook body already decoded as a dict

The rest of this release's type changes (#839, #841, #842 and the settings part of #843) only show up in mypy/basedpyright: public returns and parameters that were Any got a type, and the settings *_kwargs() return a TypedDict — reading by key and the ** splat keep working; only code that inserted a new key into the returned dict breaks. Each item, with its own migration note, is in the 0.373.0 changelog.

0.372.0 — five new tempest check rules and RuntimeError without a URL in AlembicHelper

tempest check (and tempest lint-layers) gained five rules, all with warning severity. With layers_strict = true under [tool.tempest], the tempest new default, a warning fails the command too: on a generated project with only three planted warnings, tempest lint-layers printed 3 layer finding(s): 0 error(s), 3 warning(s). and exited with code 1; with layers_strict = false, with code 0.

Rule What it flags What to do
INIT001 A def, class, call or constant in __init__.py Move it to a module of the package (router.py, factory.py, runner.py) and keep only from .x import Y as Y and __all__ in __init__.py
SIZE001 A source or test module over 1000 lines Split it by responsibility: one service into several, one test file into one per topic
LAY003 A file in controllers/, services/, repositories/ or models/ whose name repeats the layer (checkout_service.py) Rename it to checkout.py; the class stays CheckoutService
RTR005 fastapi.APIRouter(...) in a domain router, outside build_api_router Use TempestAPIRouter (from tempest_fastapi_sdk import TempestAPIRouter), which turns @raises(...) into responses=
RTR006 summary= or description= on the route decorator Move the text to an EndpointDoc constant in api/docs/<router>.py and spread it with **docs.NAME

To migrate gradually, declare the case in tests/architecture_exceptions.py with its reason (see Declared exception), or turn layers_strict off while you fix it.

RTR003 and RTR004 now recognise TempestAPIRouter and the project's router subclasses, so routers that used to pass may report new findings.

AlembicHelper without a URL: with no db_url= and no resolvable DATABASE_URL, current, current_async, has_existing_schema, adopt, sync_schema and sync_schema_async raise RuntimeError (DATABASE_URL is empty. ...) instead of sqlalchemy.exc.ArgumentError. For sync_schema and sync_schema_async this holds when there is at least one revision: with none, both return no_migrations before reading the URL, as they already did. Code that caught ArgumentError on that path catches RuntimeError instead.