Back to the universe
TypeScript LangGraph Zod SSE OpenTelemetry npm

langgraph-zod

The runtime type system and structural API boundary layer for LangGraphJS agents — deriving production-ready Zod boundary schemas directly from graph state channels.

100% Solo Engineered

the deep dive — architecture & implementation

Built and published langgraph-zod to close the gap between TypeScript's compile-time safety and the untyped world of LLM text: createGraphSchemas derives input/output/state boundary schemas from LangGraph channel definitions, a streaming-first SSE validator checks graph.streamEvents() payloads in flight at under 1ms per chunk, a framework-agnostic AgentBoundary wraps any async function or generator, adapters serve Next.js App Router, Hono, and Express routes, and OpenTelemetry hooks plus Pino/Winston serializers make validation failures observable in production. Zod v3 and v4 are both supported through a safe zod-ast introspection layer.

langgraph-zod — the boundary layer for language agents

TypeScript gives you compile-time safety; LLMs operate in the untyped world of unstructured text. langgraph-zod bridges that gap by deriving production-ready runtime boundary schemas directly from your LangGraph state channel definitions.

Feature highlights

  • Boundary Validation (createGraphSchemas): derives inputSchema and outputSchema from state definitions — omitting internal scratchpads and keys before they leak into public API output.
  • Streaming-First SSE Validation: incremental SSE parser + TransformStream validates graph.streamEvents() payloads on the fly, drops malformed chunks, and handles backpressure — at <1ms per-chunk latency.
  • Framework-agnostic AgentBoundary: wraps any async function or async generator — LangGraph, Vercel AI SDK, AutoGen TS, or plain custom agents.
  • Zod-native channel reducers (zodChannel) and self-healing LLM output parsing (safeParseLLMOutput) with repair retries.
  • Production telemetry: OpenTelemetry spans, counters (validation.error_count, channel.failed_key), and latency histograms.
  • CLI: export OpenAPI 3.1 specs and diff schemas for breaking changes in CI.

All of it in a 36 KB bundle, with adapters for Next.js, Hono, and Express.