Python · architecture
pydantic-at-boundaries
python:pydantic-at-boundaries Public function or route returns a fixed-shape untyped dictionary.
- Code
- SARJ008
- Default
- error
- Fix
- none
- Languages
- python
Why
Named boundary models make field types and required keys explicit to callers and tooling.
Fix
Return a pydantic model, frozen dataclass, or `TypedDict` for the fixed record shape.
Before / after
Executed by this rule’s unit tests.
Before
Untyped dictionary returned from a public function
from typing import Any
def build_payload(call) -> dict[str, Any]:
return {'id': call.id}
After
Named model returned from a public function
def build_payload(call) -> CallPayload:
return CallPayload(id=call.id)
Limits
- Private functions, closures, tests, fixtures, validators, and dictionary conversion methods are excluded.
- Only returned record literals and locally built fixed-shape dictionaries are recognized.