This document describes the enhanced user interface implementation for the structured output feature, addressing all user requirements for a seamless experience.
The structured output button is now always visible in the chat input, providing different states based on context:
- Purpose: Educate users about the feature and guide them through the requirements
- Behavior: Shows appropriate icon and tooltip based on current state
- Implementation: Removed conditional hiding logic
- Icon: 🔒 Lock
- Tooltip: "Structured Output requires VT+ subscription"
- Click Action: Shows upgrade dialog with pricing page redirect
- Icon: 📤 Upload
- Tooltip: "Upload a PDF document to extract structured data"
- Click Action: Shows guide dialog explaining how to use the feature
- Icon: ℹ️ Info
- Tooltip: "Switch to Gemini model to use structured output"
- Click Action: Shows dialog explaining Gemini requirement
- Icon: 💡 Lightbulb (dimmed)
- Tooltip: "Only PDF documents are supported"
- Click Action: Shows toast notification about PDF requirement
- Icon: 💡 Lightbulb
- Tooltip: "Extract structured data from PDF (Gemini only)"
- Click Action: Executes extraction with predefined prompt
- Icon: ✅ Green Lightbulb
- Tooltip: "Structured data extracted from [filename]"
- Click Action: Re-extracts or shows options
Following the AI SDK's human-in-the-loop pattern:
// User action required for each state
if (!hasStructuredOutputAccess) {
// Show upgrade dialog
setShowDialog(true);
return;
}
if (!hasDocument) {
// Show guide dialog
setShowDialog(true);
return;
}
if (!isGeminiModel) {
// Show model switch dialog
setShowDialog(true);
return;
}
// All checks passed - proceed with extraction
extractStructuredOutput();The feature uses the specified predefined prompt:
const basePrompt = 'Extract structured data from the document and return it in JSON format';
// Enhanced with context
const { object } = await generateObject({
model: google(chatMode),
schema,
prompt: `${basePrompt}
Please extract structured data from the following ${type} document.
Be thorough and accurate, extracting all relevant information.
If any field is not present in the document, omit it or mark it as optional.
${customSchema ? 'Follow the provided custom schema structure exactly.' : ''}
Document content:
${documentText}`,
});- Access: Only available for VT+ subscribers
- Integration: Seamless modal experience within the structured output flow
- Validation: Proper Zod schema validation and error handling
- Click structured output button (when eligible)
- View information dialog with feature explanation
- Optional: Click "Create Custom Schema (VT+ Only)" button
- Build custom schema in modal dialog
- Apply custom schema for extraction
The implementation follows progressive disclosure principles:
- Always Show Button: Users always see the feature exists
- Contextual Information: Click reveals what's needed to use the feature
- Step-by-Step Guidance: Clear path to enable the feature
- Educational Content: Explains how the feature works
export const StructuredOutputButton = () => {
// State management
const [showDialog, setShowDialog] = useState(false);
const [showSchemaBuilder, setShowSchemaBuilder] = useState(false);
// Feature access checks
const hasStructuredOutputAccess = useFeatureAccess(FeatureSlug.STRUCTURED_OUTPUT);
// Context-aware rendering
const getDialogContent = () => {
// Returns appropriate content based on current state
};
// Always render button with appropriate state
return (
<>
<Button onClick={handleClick}>
{/* State-based icon */}
</Button>
{/* Information Dialog */}
<Dialog>{/* ... */}</Dialog>
{/* Custom Schema Builder */}
<Dialog>{/* ... */}</Dialog>
</>
);
};Updated useStructuredExtraction to support:
- Custom schema parameter:
extractStructuredOutput(customSchema?: z.ZodTypeAny) - Predefined prompt integration
- Enhanced error handling
- Feature is always visible to all users
- Clear visual indication of availability status
- Educational tooltips guide users
- Free users see upgrade prompts
- VT+ users get full feature access
- Custom schemas available for advanced users
- Step-by-step guidance to enable feature
- Clear explanations of requirements
- Contextual help and information
- Proper ARIA labels for dialogs
- Keyboard navigation support
- Screen reader friendly tooltips
- Free User: Should see lock icon and upgrade prompt
- VT+ User, No Document: Should see upload guidance
- VT+ User, Image Document: Should see PDF requirement
- VT+ User, PDF, Non-Gemini: Should see model switch prompt
- VT+ User, PDF, Gemini: Should extract successfully
- Custom Schema: VT+ users should access schema builder
- Component state transitions
- Dialog content accuracy
- Subscription access validation
- Schema builder integration
✅ Always Visible Icon: Button shows in all states ✅ VT+ Gating: Properly restricted to Plus subscribers ✅ Document Validation: Checks for PDF attachment ✅ Model Validation: Requires Gemini model ✅ Predefined Prompt: Uses specified extraction prompt ✅ Custom Schemas: VT+ exclusive schema builder ✅ Human-in-Loop: User action required for all states ✅ Seamless Experience: Guided, educational workflow
The enhanced structured output feature is now production-ready with:
- Comprehensive error handling
- Accessibility compliance
- Progressive disclosure UX
- VT+ subscription gating
- Browser-compatible PDF processing
- Custom schema support
Implemented: June 18, 2025 Status: Production Ready ✅