Don’t wait for full generation. Catch errors mid-stream, cancel immediately, save tokens.
The Problem
Traditional Validation Flow
Streaming Validation Flow
Result: Catch bad tool names, missing params, constraint violations as they appear
How It Works
Incremental Parsing
TheStreamingValidator parses GLYPH character-by-character:
Validation Timeline
From the Streaming Validation Report:- Early Tool Detection
- Early Rejection
- Constraint Validation
- Latency Savings
Question: When do we know which tool is being called?
Tool identity known at 50% through response.
| Prompt | Tool | Detected At | Total Tokens | Detection % |
|---|---|---|---|---|
| Search for “AI news” | search | Token 6 | 12 | 50% |
| Calculate expression | calculate | Token 6 | 12 | 50% |
| Browse URL | browse | Token 6 | 12 | 50% |
| Execute command | execute | Token 6 | 11 | 55% |
Implementation
Define Tool Registry
First, register your tools with schemas:Stream and Validate
Validation Result
The validator returns detailed state:Error Detection
Early Detection Types
Unknown Tool
Unknown Tool
Detected: As soon as tool name completes (~token 6)Error Code:
UNKNOWN_TOOLAction: Cancel immediately, no need to parse argumentsMissing Tool
Missing Tool
Detected: When Error Code:
} reached without tool fieldMISSING_TOOLAction: Return error after completionType Mismatch
Type Mismatch
Detected: As soon as value type is clearError Code:
INVALID_TYPEAction: Can cancel or continue based on severityConstraint Violation
Constraint Violation
Detected: When field value completesError Codes:
CONSTRAINT_MIN: Value below minimumCONSTRAINT_MAX: Value above maximumCONSTRAINT_LEN: String too short/longCONSTRAINT_PATTERN: Regex doesn’t matchCONSTRAINT_ENUM: Not in allowed values
Missing Required
Missing Required
Detected: After parsing completesError Code:
MISSING_REQUIREDAction: Return error, cannot executeSupported Constraints
| Constraint | Type | Example | When Validated |
|---|---|---|---|
required | All | {required: true} | At completion |
min | int/float | {min: 1, max: 100} | When value complete |
max | int/float | {min: 1, max: 100} | When value complete |
minLen | string | {minLen: 1, maxLen: 500} | When string complete |
maxLen | string | {minLen: 1, maxLen: 500} | When string complete |
pattern | string | {pattern: /^https?:\/\//} | When string complete |
enumValues | string | {enumValues: ['a', 'b']} | When value complete |
Real-World Benefits
1. Cost Savings
- Token Savings
- Latency Savings
Scenario: 10% of tool calls have errorsAt scale: 1M calls/month with 10% errors = 400K tokens saved/month
2. Security
3. Resource Preparation
4. User Feedback
Advanced Patterns
Pattern 1: Allow List
Restrict tools based on context:Pattern 2: Progressive Validation
Accumulate errors instead of stopping:Pattern 3: Timeout Detection
Detect when generation stalls:Comparison: JSON vs GLYPH
| Feature | JSON Streaming | GLYPH Streaming |
|---|---|---|
| Parse complexity | Higher (state machine) | Lower (simpler syntax) |
| Tool detection | ~Token 9 | ~Token 6 (33% earlier) |
| Error recovery | Complex | Simple |
| Incremental validation | Possible but harder | Easy |
| Token efficiency | Baseline | 40-60% fewer tokens |
GLYPH’s simpler syntax makes streaming validation more reliable and easier to implement.
Performance
From the Streaming Validation Report: llama3.2:3b model:| Metric | Value |
|---|---|
| Tool detection | 50% through response |
| Token savings on rejection | 66% |
| Time savings on rejection | 33% |
| Earlier authorization | 60% earlier (105ms vs 176ms) |
| Overhead per token | <1ms |
All measurements from real LLM streaming, not synthetic tests
Summary
Early Detection
Tool name detected at 50% through response
Token Savings
Save 66% of tokens on rejected calls
Latency Reduction
33% faster error detection
Security
Catch unauthorized tools immediately
Next Steps
Format Reference
Learn GLYPH syntax
Token Savings
Understand token efficiency
Streaming Report
Full benchmark results
API Reference
Complete API documentation