alibaba/page-agent · error · InvokeError
INVALID_SCHEMA
INVALID_SCHEMA
Error message
No choices in response
What it means
The response parsed as JSON but its shape doesn't match the OpenAI chat completion schema — data.choices is missing or empty. The library expects at least one choice to extract finish_reason and content/tool calls; the raw data is attached as details for inspection.
Source
Thrown at packages/llms/src/OpenAIClient.ts:144
)
}
// 4. Parse and validate response
let data: any
try {
data = await response.json()
} catch (error) {
if ((error as any)?.name === 'AbortError') throw error
throw new InvokeError(
InvokeErrorTypes.INVALID_RESPONSE,
'Response body is not valid JSON',
error
)
}
const choice = data.choices?.[0]
if (!choice) {
throw new InvokeError(InvokeErrorTypes.INVALID_SCHEMA, 'No choices in response', data)
}
// Check finish_reason
switch (choice.finish_reason) {
case 'tool_calls':
case 'function_call': // gemini
case 'stop': // some models use this even with tool calls
break
case 'length':
throw new InvokeError(
InvokeErrorTypes.CONTEXT_LENGTH,
'Response truncated: max tokens reached',
undefined,
data
)
case 'content_filter':
throw new InvokeError(
InvokeErrorTypes.CONTENT_FILTER,View on GitHub (pinned to d02db1ee7c)
Solutions
- Inspect the attached data payload — often it contains an error object explaining the real problem
- If using a compatible gateway, verify it fully implements the choices[] contract, or test with the official OpenAI endpoint to isolate
- Upgrade or configure the gateway/proxy that is mangling the response
- Retry once — some providers intermittently return empty choices under load
Defensive patterns
Strategy: validation
Validate before calling
// probe the endpoint once for schema compatibility
const probe = await fetch(url, { method: 'POST', headers, body: JSON.stringify({ model, messages: [{ role: 'user', content: 'ping' }] }) })
const json = await probe.json()
if (!Array.isArray(json.choices) || json.choices.length === 0) throw new Error('Endpoint does not return OpenAI-compatible choices[]') Type guard
const isNoChoicesError = (e: unknown): e is InvokeError => e instanceof InvokeError && e.code === 'INVALID_SCHEMA' && /No choices/.test(e.message)
Try / catch
try {
await client.invoke(req)
} catch (e) {
if (isNoChoicesError(e)) {
console.error('Raw provider payload:', e.details) // often contains a soft error
throw e
}
throw e
} Prevention
- Smoke-test third-party 'OpenAI-compatible' gateways with a minimal request first
- Log e.details — providers often embed the real error in the body
- Prefer official endpoints when debugging schema issues
When it happens
Trigger: invoke() against an endpoint that returns 200 with an OpenAI-incompatible body: an error object like {error: {...}} with 200 status, an empty choices array (some gateways do this on internal failure), or a provider whose /chat/completions shim is incomplete.
Common situations: Third-party 'OpenAI-compatible' gateways that don't fully implement the schema; provider returning a soft error in the body with HTTP 200; model returning empty choices under load; middleware stripping parts of the response.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
AI-assisted analysis of alibaba/page-agent@d02db1ee7c (2026-08-28).
Data as JSON: /api/errors/bae4c11f2e84ced3.
Report an issue: GitHub.