Skip to content

docs(agents): make boundary-only type validation an invariant#289

Open
gbrlcustodio wants to merge 1 commit into
mainfrom
docs/type-validation-invariant
Open

docs(agents): make boundary-only type validation an invariant#289
gbrlcustodio wants to merge 1 commit into
mainfrom
docs/type-validation-invariant

Conversation

@gbrlcustodio
Copy link
Copy Markdown
Collaborator

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 isinstance guard 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:

  • Internal code trusts its annotations; a type checker is the enforcement mechanism, not runtime guards.
  • Runtime checks are warranted only where untyped or external data crosses into typed code: MCP tool signatures, and the nested un-schema'd values of dict-typed args (which is why validate_report_cards_filter's checks are legitimate and normalize_label_color's would not be).

Testing

Docs-only change. No code paths affected.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant