Skip to content

[FEAT] Add input validation to prevent errors and improve user experience #107

Description

@deepanshusingla076

Is your feature request related to a problem? Please describe.
Right now the forms don't validate user input properly. I can submit empty forms, paste huge amounts of text, or put weird characters that break things. For example:

  • Cover letter form accepts any text length (could crash AI with too much data)
  • Job title and company name have no validation
  • No checks before sending data to Gemini API
  • Forms just crash with generic errors instead of showing helpful messages

I tested the cover letter generator and was able to paste 10,000 characters in the job description field. That's way too much and probably wastes API credits.

Describe the solution you'd like
Add Zod validation schemas for all forms. The project already uses Zod for other stuff, so this fits perfectly.

I want to create validation schemas for:

  1. Cover Letter Form (app/(main)/ai-cover-letter)

    • Job title: 2-100 characters
    • Company name: 2-100 characters
    • Job description: 50-5000 characters
    • Tone: only 'professional', 'friendly', or 'formal'
  2. Onboarding Form (app/(main)/onboarding)

    • Name: 2-100 characters
    • Industry: required selection
    • Experience: 0-50 years
  3. Resume Form (app/(main)/resume)

    • Content: minimum 100 characters
    • Prevent empty submissions

Example implementation:

// lib/validations.js
import { z } from 'zod';

export const coverLetterSchema = z.object({
  jobTitle: z.string()
    .min(2, 'Job title must be at least 2 characters')
    .max(100, 'Job title is too long'),
  companyName: z.string()
    .min(2, 'Company name must be at least 2 characters')
    .max(100, 'Company name is too long'),
  jobDescription: z.string()
    .min(50, 'Job description must be at least 50 characters')
    .max(5000, 'Job description is too long (max 5000 characters)'),
  tone: z.enum(['professional', 'friendly', 'formal'])
    .default('professional'),
  fullName: z.string().min(2).max(100).optional(),
});

// Use in the form
const validated = coverLetterSchema.parse(formData);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions