For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /packs/languages/python/types.md.
Quick start

Types

Annotations describe a valid value; validation establishes whether an external value belongs to that type.

Validated models

Why

A type annotation does not validate decoded JSON or an external SDK response at runtime.

Rules

  • MUST receive untrusted values as object until runtime checks validate them. [review]
  • MUST avoid Any, unchecked casts, and type-ignore directives that bypass validation. [review]
  • MUST represent closed alternatives with typed unions, literals, or enums. [review]
  • MUST use frozen records with immutable fields for domain models. [review]
  • MUST distinguish absent values from failures that require an explanation. [review]
  • MUST use Protocols for injected capabilities when structural typing is needed. [review]
  • MUST retain explicit generic Result annotations so error types do not degrade into Any. [review]
  • MUST verify the returns decorator/composition types with its supported mypy plugin. [review]

[review]

Strict typechecks verify annotations and supported plugin inference. Boundary tests verify runtime validation.

Enforcement

Strict typechecks verify annotations and supported plugin inference. Boundary tests verify runtime validation.