Function: extractZodDescriptions()
ts
function extractZodDescriptions(schema): string[];Defined in: packages/core/src/presenter/ZodDescriptionExtractor.ts:121
Extract .describe() annotations from a Zod schema's fields.
Walks the top-level z.object() shape and retrieves the description string from each field (after unwrapping wrappers like z.optional(), z.nullable(), z.default(), etc.).
Returns an array of human-readable "fieldName: description" strings, ready to be injected as system rules.
Parameters
| Parameter | Type | Description |
|---|---|---|
schema | ZodType | A Zod schema (typically z.object, but safely handles non-objects) |
Returns
string[]
Array of "fieldName: description" strings (empty if no descriptions found)
Example
typescript
const schema = z.object({
amount_cents: z.number().describe('CRITICAL: value is in CENTS. Divide by 100.'),
currency: z.string(), // No .describe() → skipped
status: z.enum(['paid', 'pending']).describe('Show with emoji'),
});
extractZodDescriptions(schema);
// → ['amount_cents: CRITICAL: value is in CENTS. Divide by 100.',
// 'status: Show with emoji']