Show HN: langdiff – Stream valid JSON from LLMs with type-safe callbacks
11 days ago
- #Python
- #LLM
- #Streaming
- LangDiff is a Python library for streaming structured LLM outputs to frontends with intelligent partial parsing.
- It provides type-safe callbacks (on_append, on_update, on_complete) as tokens stream in.
- Supports Pydantic-style models for defining schemas and seamless interop with existing libraries like OpenAI SDK.
- Automatically generates JSON Patch diffs for efficient frontend synchronization.
- Enables building responsive AI applications with independent evolution of backend and frontend.
- Includes features like tracking mutations without changing code patterns and handling incomplete JSON tokens.
- Example use case: streaming multi-section articles with progressive updates.
- Apache-2.0 licensed with an example.py for a runnable demo.