Home/
Part XIII — Expert Mode: Systems, Agents, and Automation/40. Advanced Structured Output/40.5 Contract tests for schema compliance
40.5 Contract tests for schema compliance
Overview and links for this section of the guide.
On this page
The Contract
You need to prove that your prompt actually produces your schema.
The Tests
Write a unit test that runs against the real model (or a cached response):
test('model returns valid user schema', async () => {
const response = await model.generate(prompt);
const result = UserSchema.safeParse(response);
expect(result.success).toBe(true);
});
Run this in CI/CD. If a model update (from Google) breaks your schema adherence, you need to know before you deploy.