Intelligent Form Builder
Overview
The Intelligent Form Builder is an AI-powered form creation and design system that enables users to create sophisticated forms using natural language descriptions, intelligent field suggestions, and automated layout optimization.
Key Features
1. Natural Language to Form Generation
- Description: Simply describe the form you need in plain English
- AI Processing: Advanced AI models analyze your description and generate a complete form schema
- Example: "Create a participant enrollment form with name, email, SSN, date of birth, and signature"
- Result: Fully structured form with appropriate field types, validation, and layout
2. Intelligent Field Suggestions
- Context-Aware: AI analyzes form context and suggests appropriate field types
- Auto-Completion: Smart suggestions for field labels, placeholders, and help text
- Validation Rules: Automatic generation of validation rules based on field types
- Confidence Scores: Each suggestion includes a confidence score
3. Dynamic Layout Optimization
- AI-Powered Layout: Automatically optimizes form layout for better UX
- Responsive Design: Adapts to different screen sizes
- Completion Rate Optimization: Layouts designed to maximize form completion
- Visual Hierarchy: Intelligent field grouping and ordering
4. Real-Time AI Assistance
- Single platform AI: Form-building help is provided by the Concierge (dashboard layout, bottom-right)—one AI across the entire platform.
- Context-Aware Help: When on Form Builder, the Concierge receives page context and can guide form design, fields, and validation.
- Proactive Suggestions: Use the Concierge for step-by-step tutorials, visual explanations, and task assistance.
- Workflow Integration: Connects to workflow and compliance systems.
5. Smart Validation
- AI-Powered Validation: Intelligent validation rule generation
- Cross-Field Validation: Detects and validates relationships between fields
- Best Practice Checks: Validates against form design best practices
- Accessibility Validation: Ensures forms meet WCAG standards
6. Visual Form Builder
- Drag-and-Drop Interface: Intuitive field arrangement (palette → canvas, reorder fields on canvas)
- Live Preview: See form as you build it
- Code View: Export form schema as JSON
- Theme Customization: Multiple professional themes
Drag-and-drop stack: Implemented with @dnd-kit/core (DndContext, useDraggable, useDroppable, DragOverlay). Pointer, touch, and keyboard sensors; accessibility announcements and screen-reader instructions; drop animation. For a future API migration, see next.dndkit.com and the React migration guide (@dnd-kit/core → @dnd-kit/react).
Architecture
Components
- FormBuilder (
components/forms/form-builder.tsx)
- Main form builder interface
- Field management
- Layout configuration
- AI integration (natural language → schema; Concierge for conversational help)
- Performance: template list loads after idle (requestIdleCallback) so initial paint is not blocked; page uses next/dynamic with ssr: false to keep bundle scoped to the builder route.
- AIConcierge (dashboard layout,
components/ai-concierge.tsx)
- Single platform AI; used for form-building help when on Form Builder
- Tutorials, visual explanations, contextual help
- Form Canvas (embedded in FormBuilder)
- Visual form design
- Field positioning
- Drag-and-drop functionality
API Endpoints
- POST /api/ai/generate-form
- Generates form schema from natural language
- Uses advanced AI models (GPT-4, Claude, Gemini)
- Returns complete form structure
- POST /api/ai/optimize-form-layout
- Optimizes form layout for UX
- Analyzes field relationships
- Suggests improvements
- POST /api/ai/validate-form
- Validates form completeness
- Checks best practices
- Provides improvement suggestions
- POST /api/ai/assistant
- Conversational AI assistance
- Context-aware responses
- Action suggestions
- POST /api/forms/save
- Saves form schema to database
- Updates existing forms
- Version management
- POST /api/forms/generate
- Generates form instance from schema
- Populates from canonical data
- AI augmentation for missing fields
- GET /api/forms/templates — List template metas;
?id=returns full schema for builder. - POST /api/forms/publish — Creates FORM_DEFINITION evidence pack (schema hash, approver, change summary).
- POST /api/v1/forms/dynamic/instances — Create form instance; when
submittedByis set, a FORM_SUBMISSION evidence bundle is created automatically.
Schema metadata (workflow and evidence contracts)
- workflowContract (
schema.metadata.workflowContract): optionalworkflowId,requiredApprovals,slaHours,routingfor workflow integration. - evidenceContract (
schema.metadata.evidenceContract): optionalrequiredArtifacts,retentionYears,bundleOnSubmit. - retentionYears (
schema.metadata.retentionYears): optional retention period for submissions (years).
Evidence
- FORM_DEFINITION: created on publish (POST /api/forms/publish); exportable via evidence export (PDF/JSON).
- FORM_SUBMISSION: created when a form instance is saved with
submittedBy(status becomes submitted); links form definition, instance id, data hash, and submitter.
Field types
- Builder and renderer support: text, number, email, date, textarea, select, checkbox, radio, file, signature, section, money (with optional currency), percent, address (structured), person (name/email/phone), table (repeatable rows with columns), computed (read-only), rich_text.
Canonical store
- Save/list/read: Form definitions are stored in
form_definitions+form_versions(seeserver/forms/builder-store.ts). GET by id supports legacydocument_specificationsfallback. ETag and Cache-Control on GET schema by id for efficient revalidation. - Renderer: Lean runtime renderer in
components/forms/form-renderer.tsx; shared types inlib/forms/types.ts.
Usage
Builder Studio (mode rail)
The builder has a left-hand mode rail: Compose, Rules, Preview, Publish, Evidence.
- Compose: Natural language input, "Start from template" dropdown (loads from GET /api/forms/templates), field palette, and canvas. Choosing a template fetches the schema by id and applies it to the builder; autosave is not triggered immediately.
- Rules: List of conditional visibility, required-when, and default-value rules. Stored in
schema.metadata.rules(FormRulesDSL); applied at runtime by the renderer vialib/forms/rules-eval.ts. Add fields in Compose first, then add rules. - Preview: Renders the form with FormRenderer for a quick check.
- Publish: Create a FORM_DEFINITION evidence pack (schema hash, approver, change summary). Emits
Form.Definition.Publishedto the outbox for workflow/consumers. Save the form once before publishing. - Evidence: Links to evidence bundle created on publish; export via evidence export (PDF/JSON) for FORM_DEFINITION bundles.
Creating a Form from Natural Language
- Navigate to
/dashboard/forms/builder(or/forms/builder, which redirects there) - Enter form description in the natural language input
- Click "Generate Form"
- Review and customize the generated form
- Save or generate form instance
Manual Form Building
- Click "Add Field" buttons for different field types, or drag from the palette grip onto the design canvas (powered by @dnd-kit; pointer, touch, and keyboard supported).
- Configure field properties in sidebar (select a field to edit).
- Arrange fields on canvas: drag field cards by the grip to move; in custom grid, resize via the right/bottom edge when selected.
- Use AI suggestions for field optimization.
- Preview and validate form.
AI Assistance
- Use the Concierge (floating button, bottom-right of any dashboard page)
- Ask questions about form building; the Concierge has Form Builder context
- Get tutorials, visual explanations, and proactive suggestions
- Apply AI recommendations in the builder
AI Models Used
- GPT-4o: Form generation and optimization
- Claude 3.7 Sonnet: Complex reasoning and validation
- Gemini 2.0 Pro: Multi-modal understanding
- Model Router: Intelligent model selection based on task
Integration Points
Form Generation Engine
- Connects to
server/forms/generator.ts - Uses canonical data for population
- AI augmentation for missing fields
- RAG and KAG integration
Workflow System
- Forms trigger workflows
- State machine integration
- Evidence collection
- Approval gates
Document System
- Forms saved as document specifications
- Template generation
- Artifact creation
- Version control
Best Practices
- Be Specific: Detailed descriptions yield better forms
- Review AI Suggestions: Always review AI-generated content
- Validate Forms: Use validation before saving
- Test Preview: Check form in preview mode
- Optimize Layout: Use layout optimization for better UX
Future Enhancements
- Multi-language form generation
- Voice input for form creation
- Collaborative form editing
- Form analytics and insights
- Template library
- A/B testing for form variations
- Advanced conditional logic
- Integration with external form builders
Technical Details
Form Schema Structure
interface FormSchema {
id: string;
name: string;
description: string;
fields: FormField[];
layout: "single" | "two-column" | "three-column" | "custom";
theme?: "default" | "minimal" | "professional" | "modern";
metadata?: Record<string, unknown>;
}
Field Types Supported
- text
- number
- date
- textarea
- select
- checkbox
- radio
- file
- signature
Validation Rules
- Required fields
- Min/max values
- Pattern matching
- Custom validators
- Cross-field constraints
- Cross-year consistency
Security
- Tenant isolation
- RBAC enforcement
- Input sanitization
- XSS protection
- CSRF protection
- Rate limiting
Performance
- Lazy loading of AI suggestions
- Caching of generated forms
- Optimistic UI updates
- Real-time collaboration
- Efficient re-rendering
Accessibility
- WCAG 2.1 AA compliance
- Keyboard navigation
- Screen reader support
- Focus management
- ARIA labels
- High contrast support