// File: schema.ts // Path: apps/worker/src/raters/schema.ts // Project: AI Risk Index — airiskindex.io // Author: Simon-Pierre Boucher // Contact: contact@spboucher.ai // Copyright © 2026 Simon-Pierre Boucher. All rights reserved. // // Description: Rating response schemas (zod parse + structured-output JSON schema). import { z } from "zod"; import { DIMENSIONS } from "@airiskindex/scoring"; const RATED_DIMENSIONS = [...DIMENSIONS, "augmentation"] as const; const dimensionRating = z.object({ rating: z.number().int().min(1).max(5), rationale: z.string(), }); /** Parsed shape of one rater response (all six dimensions of one task). */ export const ratingResponseSchema = z.object( Object.fromEntries(RATED_DIMENSIONS.map((dimension) => [dimension, dimensionRating])) as Record< (typeof RATED_DIMENSIONS)[number], typeof dimensionRating >, ); export type RatingResponse = z.infer; /** * JSON schema for the structured-outputs feature (score as enum — numeric * min/max is unsupported there; docs/research/03-llm-rater-api.md). */ export const RATING_OUTPUT_JSON_SCHEMA = { type: "object", additionalProperties: false, required: [...RATED_DIMENSIONS], properties: Object.fromEntries( RATED_DIMENSIONS.map((dimension) => [ dimension, { type: "object", additionalProperties: false, required: ["rating", "rationale"], properties: { rating: { enum: [1, 2, 3, 4, 5] }, rationale: { type: "string" }, }, }, ]), ), } as const; export { RATED_DIMENSIONS };