Skip to content

polytype

One Go type. Many typed projections.

Agent quickstart

Install the skill, then tell your agent what to build

terminal
npx skills add tylergannon/polytype

Generate your first schema

Pin the Go tool, register a type, generate, validate, and commit the outputs.

Model missing and null

Choose ordinary fields, Optional[T], or Nullable[T] without guessing.

Enums and interfaces

Teach tool schemas named values and discriminated implementations.

Validate and prevent drift

Validate LLM output and make CI reject stale generated schemas.

Ship a Go ↔ JavaScript transport

Generate strict Go codecs for the devalue wire format SvelteKit speaks.

Build your own projection

Lower any Go types into the shared type grammar and emit a new target.

polytype lowers Go types, statically at go generate time, into one closed type grammar and projects it into whatever the boundary needs:

Projection How
JSON Schema, embedded in Go, for LLM tool calls and structured output go tool polytype (always on)
ValidateJSON methods --validate
Go JSON codecs: membership-checked enums and discriminated sealed unions Inferred from the types; no flag
Structural TypeScript declarations --typescript DIR, or the typescript package
devalue transport: Go runtime port plus generated typed codecs devalue, devalue/codegen packages
Your own backend grammar, typegrammar packages
  • The Go type is the single source of truth; nothing uses runtime reflection.
  • Property order follows Go struct field order, producing deterministic prompts and stable wire layouts.
  • Unknown properties are rejected: additionalProperties: false in schemas, strict decoders elsewhere.
  • Go doc comments become LLM-facing schema descriptions.
  • Ordinary and nullable fields are required; only Optional[T] removes a property from required.
  • Union discriminators and enum values are the same in every projection.
  • A shape that cannot be represented faithfully fails generation with a diagnostic naming the type or field, instead of widening to any.
  • Generated files are safe to commit and verify in CI.

Need exact exported signatures? The generated Go API reference is available, but most integrations should begin with Getting started.