← back

Pragmatic AI with TypeChat: Daniel Rosenwasser

2.2K views · Nov 14, 2023 · 18:33 min · Watch on YouTube ↗
Takeaway

Use TypeScript types as both schema guidance and validator-driven repair loop to make LLM JSON outputs reliably consumable by typed application code.

Summary

  • Daniel Rosenwasser (TypeScript PM) introduces TypeChat, an npm library that bridges LLM outputs to traditional apps via TypeScript types.
  • Insight: types are both guidance for the model (interface definitions in the prompt) and validators of the response — TypeScript compiler runs the actual JSON validation.
  • On validation failure, the compiler error message becomes the repair prompt: the model is asked to fix the typed output until it parses cleanly.
  • Demo: a coffee-shop schema under 40 lines lets natural language orders ('one latte with foam') parse into well-typed JSON; ambiguous inputs ('purple gorilla named Bonsai') land in an `unknown_text` field for graceful recovery.
  • Shifts the practice from prompt engineering to schema engineering, threading typed results into traditional app logic.
typescriptstructured-outputtypechat
Original description
The recent wave of AI has created a frenzy to take radically different approaches to what we can build. The underlying LLMs, however, work off an incomplete canvas and dream up pictures and prose as they please. That’s great for chat apps, but what about the millions of applications out there today? Many can benefit from natural interfaces, but our code fundamentally expects structure. TypeChat is our experimental library to bridge the unstructured output of language models to the structured world of our code.

Recorded live in San Francisco at the AI Engineer Summit 2023. See the full schedule of talks at https://ai.engineer/summit/schedule & join us at the AI Engineer World's Fair in 2024! Get your tickets today at https://ai.engineer/worlds-fair

About Daniel Rosenwasser
Daniel is the Product Manager of the TypeScript programming language and more recently has been experimenting with TypeChat. He has a passion for programming languages, type systems, runtimes, and building great tooling for developers.