docs(agents): make boundary-only type validation an invariant#289
Conversation
release: v0.2.0-beta.3
Codify that static typing is the contract for internal code and runtime isinstance guards belong only at trust boundaries (MCP tool signatures, nested values of dict-typed args), not inside internal functions. Prevents per-function defensive type checks from becoming the norm; the enforcement mechanism for internal type contracts is a type checker, not hand-written guards.
There was a problem hiding this comment.
Clear, well-motivated docs change.
The invariant matches how the codebase already behaves: scalar args are coerced at the MCP shell (color: str via FastMCP/pydantic), SDK planners like normalize_label_color trust the annotation, and nested JSON under dict-typed args is where runtime shape checks (validate_report_cards_filter) legitimately live. CI is green; nothing blocking merge.
Static review only (docs-only diff).
Also noted
** CLI as a boundary peer:** The MCP example lands well. Since the same SDK planners are called from CLI (color: str on Typer options in pipefy_cli), a short parallel note that CLI signatures are the same kind of trust boundary would keep MCP/CLI parity reviews aligned — optional polish, not a merge blocker.
|
Added in 5aeb430: a parallel bullet noting the CLI command signature (Typer options like |
Summary
Adds a coding-style invariant to
AGENTS.md: type validation belongs at trust boundaries, not inside internal functions.Why
A PR review (#280) flagged a missing
isinstanceguard inside a pure SDK planner (normalize_label_color). On inspection the guard was redundant: the MCP tool signature (color: str, FastMCP/pydantic-backed) already coerces and rejects the scalar at the boundary, so the planner behind it can trust its annotation. Hand-guarding every internal function reinvents dynamic typing and, once accepted, becomes the expectation everywhere.The invariant draws the line explicitly:
dict-typed args (which is whyvalidate_report_cards_filter's checks are legitimate andnormalize_label_color's would not be).Testing
Docs-only change. No code paths affected.