Creates a validator that checks ChatGPT Web responses against a strict JSON schema.
// Source: https://github.com/miuuyy/codex-chatgpt-web | License: MIT | Copyright 2026 codex-chatgpt-web contributors
// Provided via justclaw.it.com; keep this notice with the code.
import Ajv, { type ValidateFunction } from "ajv";
import addFormats from "ajv-formats";
import type { CodexJsonSchemaOutputFormat } from "../../types";
import { ChatGptWebAdapterError } from "./adapter-error";
export type ChatGptStructuredOutputValidator = (answer: string) => void;
function validationError(message: string): ChatGptWebAdapterError {
return new ChatGptWebAdapterError(message, {
status: 502,
errorType: "server_error",
code: "structured_output_validation_failed",
retryable: false,
});
}
export function createChatGptStructuredOutputValidator(
format: CodexJsonSchemaOutputFo
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key