json-render
AI chat response rendering guidance — handling UIMessage parts, tool call displays, streaming states, and structured data presentation. Use when building custom chat UIs, rendering tool results, or troubleshooting AI response display issues.
Best use case
json-render is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
AI chat response rendering guidance — handling UIMessage parts, tool call displays, streaming states, and structured data presentation. Use when building custom chat UIs, rendering tool results, or troubleshooting AI response display issues.
Teams using json-render should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/json-render/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How json-render Compares
| Feature / Agent | json-render | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
AI chat response rendering guidance — handling UIMessage parts, tool call displays, streaming states, and structured data presentation. Use when building custom chat UIs, rendering tool results, or troubleshooting AI response display issues.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# AI Chat Response Rendering
You are an expert in rendering AI SDK v6 chat responses — UIMessage parts, tool call results, streaming states, and structured data display in React applications.
## The Problem
When building chat interfaces with AI SDK v6, the raw message format includes multiple part types (text, tool calls, reasoning, images). Without proper rendering, responses appear as raw JSON or malformed output.
## AI SDK v6 Message Format
In v6, messages use the `UIMessage` type with a `parts` array:
```ts
interface UIMessage {
id: string
role: 'user' | 'assistant'
parts: UIMessagePart[]
}
// Part types:
// - { type: 'text', text: string }
// - { type: 'tool-<toolName>', toolCallId: string, state: string, input?: unknown, output?: unknown }
// state values: 'partial-call' | 'call' | 'output-available' | 'approval-requested' | 'approval-responded' | 'output-denied'
// - { type: 'reasoning', text: string }
// - { type: 'step-start' } // internal, skip in rendering
```
## Recommended: Use AI Elements
The simplest approach is to use AI Elements, which handles all part types automatically:
```tsx
import { Message } from '@/components/ai-elements/message'
import { Conversation } from '@/components/ai-elements/conversation'
{messages.map((message) => (
<Message key={message.id} message={message} />
))}
```
⤳ skill: ai-elements — Full component library for AI interfaces
## Manual Rendering Pattern
If you need custom rendering without AI Elements, follow this pattern:
```tsx
'use client'
import { useChat } from '@ai-sdk/react'
import { DefaultChatTransport } from 'ai'
export function Chat() {
const { messages, sendMessage, status } = useChat({
transport: new DefaultChatTransport({ api: '/api/chat' }),
})
const isLoading = status === 'streaming' || status === 'submitted'
return (
<div>
{messages.map((message) => (
<div key={message.id}>
{message.parts?.map((part, i) => {
// 1. Text parts — render as formatted text
if (part.type === 'text' && part.text.trim()) {
return (
<div key={i} className={
message.role === 'user'
? 'bg-primary text-primary-foreground rounded-lg px-3 py-2'
: 'bg-muted rounded-lg px-3 py-2'
}>
{part.text}
</div>
)
}
// 2. Tool parts — type is "tool-<toolName>"
if (part.type.startsWith('tool-')) {
const toolPart = part as {
type: string
toolCallId: string
state: string
input?: unknown
output?: unknown
}
const toolName = toolPart.type.replace('tool-', '')
if (toolPart.state === 'output-available' && toolPart.output) {
return <ToolResultCard key={i} name={toolName} output={toolPart.output} />
}
if (toolPart.state === 'output-denied') {
return (
<div key={i} className="text-sm text-muted-foreground">
{toolName} was denied
</div>
)
}
if (toolPart.state === 'approval-requested') {
return (
<div key={i} className="text-sm text-yellow-500">
{toolName} requires approval
</div>
)
}
return (
<div key={i} className="text-sm text-muted-foreground animate-pulse">
Running {toolName}...
</div>
)
}
// 3. Reasoning parts
if (part.type === 'reasoning') {
return (
<details key={i} className="text-xs text-muted-foreground">
<summary>Thinking...</summary>
<p className="whitespace-pre-wrap">{(part as { text: string }).text}</p>
</details>
)
}
// 4. Skip unknown types (step-start, etc.)
return null
})}
</div>
))}
</div>
)
}
```
## Rendering Tool Results as Cards
Instead of dumping raw JSON, render structured tool output as human-readable cards:
```tsx
function ToolResultCard({ name, output }: { name: string; output: unknown }) {
const data = output as Record<string, unknown>
// Pattern: Check for known result shapes and render accordingly
if (data?.success && data?.issue) {
const issue = data.issue as { identifier?: string; title?: string }
return (
<div className="rounded border border-border bg-card p-2 text-sm">
<span className="font-medium text-green-400">
{name === 'createIssue' ? 'Created' : 'Updated'} {issue.identifier}
</span>
<p className="text-muted-foreground">{issue.title}</p>
</div>
)
}
if (data?.items && Array.isArray(data.items)) {
return (
<div className="rounded border border-border bg-card p-2 text-sm">
<p className="font-medium">{data.items.length} results</p>
{data.items.slice(0, 5).map((item: Record<string, unknown>, i: number) => (
<p key={i} className="text-muted-foreground">{String(item.name || item.title || item.id)}</p>
))}
</div>
)
}
if (data?.error) {
return (
<div className="rounded border border-destructive/30 bg-destructive/10 p-2 text-sm text-destructive">
{String(data.error)}
</div>
)
}
// Fallback: simple completion message (not raw JSON)
return (
<div className="rounded border border-border bg-card p-2 text-xs text-muted-foreground">
{name} completed
</div>
)
}
```
## Server-Side Requirements
The server route must use the correct v6 response format:
```ts
// app/api/chat/route.ts
import { streamText, convertToModelMessages, gateway } from 'ai'
export async function POST(req: Request) {
const { messages } = await req.json()
// IMPORTANT: convertToModelMessages is async in v6
const modelMessages = await convertToModelMessages(messages)
const result = streamText({
model: gateway('anthropic/claude-sonnet-4.6'),
messages: modelMessages,
})
// Use toUIMessageStreamResponse for chat UIs (not toDataStreamResponse)
return result.toUIMessageStreamResponse()
}
```
## Client-Side Requirements
```tsx
import { useChat } from '@ai-sdk/react'
import { DefaultChatTransport } from 'ai'
const { messages, sendMessage, status } = useChat({
// v6 uses transport instead of api
transport: new DefaultChatTransport({ api: '/api/chat' }),
})
// v6 uses sendMessage instead of handleSubmit
sendMessage({ text: inputValue })
// Status values: 'ready' | 'submitted' | 'streaming'
const isLoading = status === 'streaming' || status === 'submitted'
```
## Common Mistakes
### 1. Raw JSON in chat responses
**Cause**: Rendering `message.content` instead of iterating `message.parts`.
**Fix**: Always iterate `message.parts` and handle each type:
```tsx
// WRONG — shows raw JSON
<div>{message.content}</div>
// RIGHT — renders each part type
{message.parts?.map((part, i) => {
if (part.type === 'text') return <span key={i}>{part.text}</span>
// ... handle other types
})}
```
### 2. Tool results showing as JSON blobs
**Cause**: Using `JSON.stringify(output)` as the display.
**Fix**: Create structured card components for known tool output shapes.
### 3. "Invalid prompt: messages do not contain..." error
**Cause**: Not converting UI messages to model messages on the server.
**Fix**: Use `await convertToModelMessages(messages)` — it's async in v6.
### 4. Messages not appearing / empty responses
**Cause**: Using `toDataStreamResponse()` instead of `toUIMessageStreamResponse()`.
**Fix**: Use `toUIMessageStreamResponse()` when the client uses `useChat` with `DefaultChatTransport`.
### 5. useChat not working with v6
**Cause**: Using the v5 `useChat({ api: '/api/chat' })` pattern.
**Fix**: Use `DefaultChatTransport`:
```tsx
// v5 (old)
const { messages, handleSubmit, input } = useChat({ api: '/api/chat' })
// v6 (current)
const { messages, sendMessage, status } = useChat({
transport: new DefaultChatTransport({ api: '/api/chat' }),
})
```
## Decision Tree
```
Building a chat UI with AI SDK v6?
└─ Want pre-built components?
└─ Yes → Use AI Elements (⤳ skill: ai-elements)
└─ No → Manual rendering with parts iteration
└─ Tool results look like JSON?
└─ Create ToolResultCard components for each tool's output shape
└─ Text not rendering?
└─ Check part.type === 'text' and use part.text
└─ Server errors?
└─ Check: await convertToModelMessages(), toUIMessageStreamResponse()
```
## Server-Side Message Validation
Use `validateUIMessages` to validate incoming messages before processing:
```ts
import { validateUIMessages, convertToModelMessages, streamText, gateway } from 'ai'
export async function POST(req: Request) {
const { messages } = await req.json()
const validatedMessages = validateUIMessages(messages)
const modelMessages = await convertToModelMessages(validatedMessages)
// ...
}
```
## Official Documentation
- [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui)
- [useChat Reference](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot)
- [UIMessage Types](https://ai-sdk.dev/docs/reference/ai-sdk-core/ui-message)
- [AI Elements](https://ai-sdk.dev/elements)Related Skills
workflow
Vercel Workflow DevKit (WDK) expert guidance. Use when building durable workflows, long-running tasks, API routes or agents that need pause/resume, retries, step-based execution, or crash-safe orchestration with Vercel Workflow.
verification
Full-story verification — infers what the user is building, then verifies the complete flow end-to-end: browser → API → data → response. Triggers on dev server start and 'why isn't this working' signals.
vercel-storage
Vercel storage expert guidance — Blob, Edge Config, and Marketplace storage (Neon Postgres, Upstash Redis). Use when choosing, configuring, or using data storage with Vercel applications.
vercel-services
Vercel Services — deploy multiple services within a single Vercel project. Use for monorepo layouts or when combining a backend (Python, Go) with a frontend (Next.js, Vite) in one deployment.
vercel-sandbox
Vercel Sandbox guidance — ephemeral Firecracker microVMs for running untrusted code safely. Supports AI agents, code generation, and experimentation. Use when executing user-generated or AI-generated code in isolation.
vercel-queues
Vercel Queues guidance (public beta) — durable event streaming with topics, consumer groups, retries, and delayed delivery. $0.60/1M ops. Powers Workflow DevKit. Use when building async processing, fan-out patterns, or event-driven architectures.
vercel-functions
Vercel Functions expert guidance — Serverless Functions, Edge Functions, Fluid Compute, streaming, Cron Jobs, and runtime configuration. Use when configuring, debugging, or optimizing server-side code running on Vercel.
vercel-flags
Vercel Flags guidance — feature flags platform with unified dashboard, Flags Explorer, gradual rollouts, A/B testing, and provider adapters. Use when implementing feature flags, experimentation, or staged rollouts.
vercel-firewall
Vercel Firewall and security expert guidance. Use when configuring DDoS protection, WAF rules, rate limiting, bot filtering, IP allow/block lists, OWASP rulesets, Attack Challenge Mode, or any security configuration on the Vercel platform.
vercel-cli
Vercel CLI expert guidance. Use when deploying, managing environment variables, linking projects, viewing logs, managing domains, or interacting with the Vercel platform from the command line.
vercel-api
Vercel MCP and REST API expert guidance. Use when the agent needs live access to Vercel projects, deployments, environment variables, domains, logs, or documentation through the MCP server or REST API.
vercel-agent
Vercel Agent guidance — AI-powered code review, incident investigation, and SDK installation. Automates PR analysis and anomaly debugging. Use when configuring or understanding Vercel's AI development tools.