Why my AI assistant answers with cards, not paragraphs
Last November I asked an AI app to split a hotpot dinner for three people, including VAT and drinks. It returned twelve lines of bullet points and arithmetic. Five minutes later, a fourth friend chipped in for dessert, s
Last November I asked an AI app to split a hotpot dinner for three people, including VAT and drinks. It returned twelve lines of bullet points and arithmetic. Five minutes later, a fourth friend chipped in for dessert, so I either had to type another prompt or copy the numbers into Calculator.
That pattern kept repeating on my phone. Packing lists went into Notes. Trip plans went into Calendar. Vocabulary drills turned into messy scrolling back and forth. Text is a flexible format for asking a question, and a clumsy format for acting on the answer on a 6-inch screen.
While building Piu, an iOS and iPadOS AI assistant I work on alone from Vietnam, I decided the chat stream should return native SwiftUI views whenever an answer has clear structure. I call them Reply Cards.
One fenced JSON block, validated before the client sees it
Each model reply is ordinary prose with at most one fenced block tagged piu-card sitting between an optional intro and outro:
Here is the breakdown for dinner.
```piu-card
{
"type": "split",
"title": "Hotpot dinner",
"currency": "VND",
"lines": [
{ "label": "Hotpot set", "amount": 450000 },
{ "label": "Drinks", "amount": 120000 },
{ "label": "Dessert", "amount": 90000 }
],
"people": 3
}
```
Tap + or - if another person joins.
The backend runs a strict parser on the finished output before saving the message. The payload must stay under 16 KiB, reject unknown fields, stay within item limits (for example 1 to 12 bill lines and 1 to 50 people), and pass per-card normalization.
Every card type also compiles to a deterministic plain-text fallback on the server. When the model drops a closing brace or invents a field name, the parser strips the broken fence and posts the readable prose or fallback instead. A user never sees raw JSON in a chat bubble. That same plain-text fallback doubles as the searchable text in chat history, the copy-to-clipboard representation, and the encrypted 24-hour offline cache.
On iOS, streaming brings a second hazard: tokens arrive line by line, so the raw opening fence would flash on screen before the JSON finishes. A small stream parser watches incoming lines, hides anything once the opening piu-card fence begins (including partial four-character prefixes on the trailing line), and swaps in a card skeleton until the validated payload arrives.
Choosing 16 cards from everyday phone questions
I avoided building a general-purpose widget engine or letting the model emit arbitrary HTML. Every card maps to a concrete iPhone task people ask for every day:
- Money and decisions: Split the bill (with a live per-person stepper), Compare options (2 to 3 columns with badges), Decision wheel (for "what's for lunch?"), and Quick chart.
- Travel and scheduling: Day-by-day Trip itinerary (with day tabs, Apple Maps queries, and reminder presets), Countdown, Calendar event, and Contact card.
- Daily work and home: Checklists with completion state, Step-by-step recipes (with one-tap timers attached to waiting steps), Focus timers, and Unit converter.
- Language and study: Flashcards with IPA pronunciation and Again / Got it tracking, Pronunciation breakdowns with syllable stress, and Multiple-choice quizzes with explanations.
- Onboarding: A first-chat Setup guide card.
Every interactive card takes one shared SwiftUI input contract: the immutable card model, the persisted user state (for example checked boxes or the current head count on a bill split), a debounced save closure, and callbacks for haptics, toasts, or opening a reminder sheet. Tapping + on a bill split updates the per-person math on device and debounces the state write in the background.
The hard parts
1. Deciding when to salvage vs reject a card
My first validator rejected any card that exceeded a character cap. In production, models stuffed an entire ingredient list into a recipe card's one-line metadata field, or wrote verbose itinerary tab headers like "Day 1: Old Town, river lanterns and street food". Rejecting the whole block threw away a good answer and left the user with plain text.
I split validation into two buckets:
- Display-only labels (titles, badges, day tabs, notes): trim to fit. For day tabs, keep the prefix before a colon or dash when it fits; otherwise trim with an ellipsis. For an oversized recipe metadata field (>80 characters), hoist that text into the intro paragraph above the card so the reader keeps the ingredient list and still gets the interactive recipe steps.
- Actionable fields (checklist rows, quiz options, reminder or calendar payloads): validate without trimming. Never drop characters from text that the app might save to a reminder or that changes an answer choice.
Knowing when to skip a card mattered as much as validating one. A quick factual question or a personal reflection reads better as plain text. Over-triggering cards turns a quiet chat into a slideshow.
2. Accessibility sizes (AX5), dark mode, and the keyboard
Chat bubbles are narrow on an iPhone SE or Mini. At the largest Dynamic Type setting (AX5), an uncapped SwiftUI card explodes past the bubble margins: prices collide with item names, chip labels clip, and three-column comparisons collapse into single vertical letters.
Three layout rules fixed most of it, and shipping 1.0.4 forced a fourth round of fixes at the extreme end:
-
Cap card type scaling at
AX2while letting surrounding prose keep scaling. The intro and outro text still honorsAX5; inside the card container, custom scaled metrics stop ataccessibility2so rows stay legible without breaking alignment. In 1.0.4 I also tracked down and fixed a crash that only triggered when opening a chat at the largest iOS text size. -
Reflow horizontal pairs into vertical stacks at accessibility sizes. In the bill splitter, each line is an
HStackof label and monospaced-digit amount at standard sizes. WhendynamicTypeSize.isAccessibilitySizeis true, that row flips to aVStackso both the item description and the VND or USD figure get the full width. - Keep the composer usable next to tall cards. When the keyboard opens, expanded cards take over the whole viewport. Collapsing them into a one-line pill while typing keeps the message box reachable, with a tap to expand if you need to check a number mid-sentence. In 1.0.4 I also pinned the message field above the keyboard when attaching a photo, replying to a message, or writing a long draft, including in landscape and at large text sizes, and added one-tap Yes/No quick actions whenever the assistant asks a yes/no question.
Dark mode caught a different bug: early card surfaces relied on subtle gray borders that disappeared on OLED black. Moving every card onto semantic surface and hairline tokens kept separation clear in both light and dark themes without hard-coded colors.
What I would do differently
-
Start with five cards, not sixteen. Building the streaming parser, validation split, state persistence, and
AX2layout rules on five diverse cards (Checklist, Split, Itinerary, Flashcards, Compare) would have caught 90% of the design flaws earlier. -
Test Vietnamese diacritics and long currencies first. A VND total like
1.450.000 VNDtakes far more horizontal width than$58, and Vietnamese stacked tone marks clip faster when line heights are tight. Testing English first hid layout bugs that showed up right away in Vietnamese. - Write the plain-text fallback before the SwiftUI view. Treating the fallback as an afterthought led to mismatched formatting between the card and copied text. Writing it first forced every card schema to stay minimal.
If you want to see how all 16 cards behave on a real iPhone or iPad, the overview is at askpiu.com/reply-cards and Piu 1.0.4 is free on the App Store (iOS and iPadOS 17+, English and Vietnamese, with a 7-day free Pro trial).
If you build structured UI inside LLM chats on mobile, how do you handle streaming partial payloads and large Dynamic Type sizes?
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.