Validation & structured output
Validate without Zod
validation() only needs a safeParse() method matching Zod's shape -- write your own if you don't want the dependency.
← All recipes
import { Klaro, validation, type ZodLikeSchema } from "@klaroshield/sdk";
interface Invoice { total: number; currency: string }
const InvoiceSchema: ZodLikeSchema<Invoice> = {
safeParse(data: unknown) {
const d = data as Invoice;
if (typeof d?.total === "number" && typeof d?.currency === "string") {
return { success: true, data: d };
}
return { success: false, error: "missing total or currency" };
},
};
const klaro = new Klaro().use(validation({ schema: InvoiceSchema }));Checked against the shipped @klaroshield/sdk API. Full docs at klaro.services/klaroshield/docs.