🦄 Generative UIs and Structured Streaming
We'll explore hard problems in building rich UIs that rely on streaming data from LLMs. ​Specifically, we'll talk through techniques for rendering **STRUCTURED** outputs from LLMs, with real-world examples of how to handle partially-streamed outputs over incomplete JSON data. We'll explore advanced needs like * Fields that should be required for stream to start * ​Rendering React Components with partial data ​* Handling nullable fields vs. yet-to-be-streamed fields * ​Building high-quality User feedback * ​Handling errors mid-stream
Project Details
Open in GitHubMoving beyond basic token-by-token streaming to create fluid, interactive, and truly modern AI user experiences with semantic streaming of structured objects.
Episode Summary
This week's 🦄 ai that works session dove into one of the most underrated aspects of building great AI apps: Streaming.
We explored how to go beyond basic token-by-token streaming to create fluid, interactive, and truly modern user experiences. The session covered practical implementations using NextJS, FastAPI, and more, demonstrating how semantic streaming can transform your AI applications.
The key insight: streaming isn't just about showing text faster—it's about building better apps. By streaming semantically valid, partial objects instead of broken JSON chunks, you can create interactive UIs that respond in real-time and give users control.
The One Thing to Remember
The difference between a good and a great AI app is often the user experience. Move beyond streaming raw tokens and start streaming structured, semantically valid objects. It simplifies your frontend code and unlocks a new level of interactivity for your users.
Key Takeaways
- Stop Streaming Broken JSON: The BAML approach provides a stream of semantically valid, partial objects, so at every step, your application has a real, usable data structure to work with
- Control Your Stream Declaratively: Control streaming behavior directly in your BAML schema with simple attributes like
@@stream.done
to ensure objects only appear once they're fully formed - Streaming is a UX Superpower: Create interactive UIs that respond in real-time and give users control, not just show text faster
- Enable Parallel Workflows: Get complete, validated objects as they're generated, allowing downstream tasks to start immediately while generation continues
Live Demos
- Recipe Generator Demo - See semantic streaming in action
- Interactive Todo List - Experience real-time structured updates