ValentinNikolaev/agent-skills / agent-plugins/skills/zod
zod
VerifiedImplement version-aware Zod schemas and runtime parsing; not diff review or library selection.
| File | Kind | Size |
|---|---|---|
| LICENSE.secondsky-claude-skills | other | 1.1 KB |
| SKILL.md | skill md | 4.9 KB |
| agents/openai.yaml | config | 297 B |
| references/parsing-contracts.md | markdown | 2.8 KB |
| references/version-boundaries.md | markdown | 1.8 KB |
references/parsing-contracts.md
View on GitHub# Parsing Contracts
This self-contained example targets Zod 4.4.3 and TypeScript 5.9.3 for reproducible verification. It uses Zod 4 APIs and codecs introduced in 4.1; test other supported versions explicitly. Do not replace an existing project's dependency versions to match the example.
```typescript
import { z } from "zod";
export const UserSchema = z.strictObject({
name: z.string().trim().min(1),
age: z.coerce.number<string | number>().int().min(18),
email: z.email(),
role: z.enum(["member", "admin"]).default("member"),
});
export type UserInput = z.input<typeof UserSchema>;
export type User = z.output<typeof UserSchema>;
export type ParsedUser =
| { kind: "valid"; data: User }
| { kind: "invalid-json" }
| { kind: "invalid-data"; issues: z.core.$ZodIssue[] };
export function parseUserJson(text: string): ParsedUser {
let value: unknown;
try {
value = JSON.parse(text);
} catch {
return { kind: "invalid-json" };
}
const parsed = UserSchema.safeParse(value);
if (!parsed.success) return { kind: "invalid-data", issues: parsed.error.issues };
return { kind: "valid", data: parsed.data };
}
export const DefaultsSchema = z.object({
name: z.string().default("Anonymous").optional(),
});
export const CountsSchema = z.record(z.string(), z.number().int());
export const UsernameSchema = z.string().refine(
async (name) => name !== "taken",
{ error: "Username unavailable" },
);
export const DateCodec = z.codec(z.iso.datetime(), z.date(), {
decode: (iso) => new Date(iso),
encode: (date) => date.toISOString(),
});
```
Test these independently observed outcomes:
- Malformed JSON returns `invalid-json`; a valid JSON string with the wrong shape returns `invalid-data`.
- A valid user with age `"20"` returns numeric age 20, a trimmed name, and default role `member`. Reject extra fields under this explicit strict-object contract.
- Parsing does not normalize the original input in place. Use the parsed `data`; returning only `success` cannot make a transforming schema a sound output-type predicate over the original object.
- `DefaultsSchema.parse({})` returns `{ name: "Anonymous" }` under this Zod version. `CountsSchema` rejects a string count.
- Await `UsernameSchema.safeParseAsync(...)` and observe both success and validation failure. The example's callback performs no network request; an actual availability lookup also needs an infrastructure-error policy.
- Decode a valid ISO timestamp to a Date and encode it to the expected ISO string. Reject invalid ISO strings and invalid Dates with the relevant safe methods. Normalization may make string round trips differ from their original spelling.
JSON syntax failures and expected schema failures are intentionally separate. Unexpected exceptions from custom callbacks are not silently converted into schema success or a generic invalid-input response.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |