Skip to main content
Back to Prompt Library
implementation

Create Vercel AI SDK Structured Extractor

Inspect the original prompt language first, then copy or adapt it once you know how it fits your workflow.

Linked challenge: Automated Document KYC Extraction Pipeline with Vercel AI SDK

Format
Code-aware
Lines
19
Sections
3
Linked challenge
Automated Document KYC Extraction Pipeline with Vercel AI SDK

Prompt source

Original prompt text with formatting preserved for inspection.

19 lines
3 sections
No variables
0 checklist items
import { generateObject } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const kycSchema = z.object({
  fullName: z.string(),
  documentNumber: z.string(),
  dateOfBirth: z.string(),
  expirationDate: z.string(),
  address: z.string().optional(),
  mrzChecksumValid: z.boolean()
});

export async function extractKYCData(documentText: string) {
  const result = await generateObject({
    model: openai('gpt-4o'),
    schema: kycSchema,
    prompt: `Extract structured KYC fields from the following document OCR text: ${documentText}`
  });
  return result.object;
}

Adaptation plan

Keep the source stable, then change the prompt in a predictable order so the next run is easier to evaluate.

Keep stable

Hold the task contract and output shape stable so generated implementations remain comparable.

Tune next

Update libraries, interfaces, and environment assumptions to match the stack you actually run.

Verify after

Test failure handling, edge cases, and any code paths that depend on hidden context or secrets.