Overview
core-ai provides a hierarchy of error classes for handling different types of failures when working with language models. All errors extend fromCoreAIError and provide structured error information.
Error Hierarchy
CoreAIError
Base error class for all core-ai errors.ValidationError
Thrown when core-ai rejects invalid caller input or local request configuration before calling a provider. This includes schemas core-ai cannot use: a tool’sparameters or a structured output schema that cannot be converted to JSON Schema, a Standard Schema without JSON Schema support, or a value that is neither kind of schema. The message names the tool or schema, and cause holds the schema library’s conversion error when there is one.
With tool discovery in use, it also covers the discovery rules:
- A tool or discovered tool named
core_ai_discover_toolsorcore_ai_deferred_tools_placeholder, which core-ai reserves. - A discovery call without a
tool-discoverymessage answering it before the next user or assistant message. - A
tool-discoverymessage that answers no discovery call of the preceding assistant message, or answers a call that is already answered. - A discovery call whose
idanother call of the same assistant message also uses. - A
tool-discoverymessage with bothtoolsand anote. - A
tool-discoverymessage that lists the same tool name more than once. - A discovered tool whose
namesome provider rejects. - A discovered tool whose
parametersare not plain JSON Schema, or not an object schema withtype: "object"at the root. - A
toolChoicethat names a tool outsidetools.
Properties
string
Error message describing what went wrong.
unknown
Optional underlying cause of the error (e.g., network error, API error).
string | undefined
Optional provider context when the error can be attributed to a provider.
string
Error name, always
'ValidationError'.Example
ToolSchemaStrictnessError
Thrown before the provider request when astrict: true tool is unsupported,
exceeds a provider limit, or has a schema outside the strict-capable contract.
Extends ValidationError.
Properties
string
Provider that rejected the local configuration.
string
Model ID used for capability resolution.
readonly string[]
Tools that requested strict enforcement.
ToolSchemaStrictnessErrorReason
Machine-readable failure category.
unsupported means the model does not
support strict tool schemas. limit-exceeded means the request contains
more strict tools than the provider allows. union-limit-exceeded means the
strict tools have more union-typed parameters than the provider allows.
invalid-schema means a strict tool’s schema is outside the strict-capable
contract.number | undefined
Provider limit when
reason is limit-exceeded.number | undefined
Provider limit when
reason is union-limit-exceeded.number | undefined
Union-typed parameters across the request’s strict tools when
reason is
union-limit-exceeded. toolNames then lists the strict tools that have
any.readonly StrictToolSchemaViolation[] | undefined
When
reason is invalid-schema, one entry per offending schema path with
a fix hint. Also available directly through the exported
getStrictToolSchemaViolations() helper.Example
validateToolCall() for Standard
Schema tools, or validate them yourself for plain JSON Schema tools, before
execution.
UnsupportedInputModalityError
Thrown when user messages include content parts the model does not accept, before the provider call. ExtendsValidationError.
Properties
readonly string[]
Modalities present in the user messages.
readonly string[]
Modalities from
model.capabilities.modalities.input.readonly string[]
Requested modalities missing from the model capabilities.
Example
UnsupportedSystemMessagePlacementError
Thrown when a system message sits where the model does not accept one, before the provider call. The rule comes frommodel.capabilities.messages.systemPlacement. Extends ValidationError.
Properties
'leading' | 'before-reply' | 'anywhere'
The model’s rule for system messages after the first non-system message.
readonly SystemMessagePlacementIssue[]
Each offending system message, by its index in
messages, with the rule it
breaks. The error message includes a fix for each one.getSystemMessagePlacementIssues(messages, placement) helper. See
System message placement.
Example
AbortedError
Thrown when an operation is cancelled via anAbortSignal.
StreamAbortedError
Thrown when a streaming operation is aborted via anAbortSignal.
Example
ProviderError
Error for provider/API failures. Discriminate with subclasses andinstanceof. Transient failures extend RetryableProviderError.
Properties
string
The provider that threw the error (e.g.,
'openai', 'anthropic').number | undefined
HTTP status code if available (e.g.,
404, 500, 429).Classified subclasses
Each provider
wrap*Error helper decides which subclass to throw from SDK-specific fields (error types, status codes, message shapes). Use instanceof to branch in application code — statusCode is for logging and debugging, not for retry decisions.
HTTP 429 is not always RateLimitError: billing quota (for example OpenAI insufficient_quota) remains a non-retryable ProviderError, while some capacity signals (for example Azure NoCapacity) map to ModelOverloadedError. RateLimitError.retryAfterSeconds may come from Retry-After, Azure retry-after-ms, or an HTTP-date Retry-After header.
Example
StructuredOutputError
Base class for errors related to structured output generation (objects).Properties
string | undefined
The raw output from the model that failed to parse/validate.
Example
StructuredOutputNoObjectGeneratedError
Thrown when the model doesn’t generate an object at all.Example
StructuredOutputParseError
Thrown when the model’s output cannot be parsed as JSON.Example
StructuredOutputValidationError
Thrown when the model’s output doesn’t match a Standard Schema passed asschema to generateObject() or streamObject(). Plain JSON Schema output is never validated by core-ai, so it never raises this error.
Properties
string[]
Validation messages from the schema library, each formatted as
path.to.key: message. Issues at the root use <root> as the path.Example
Error Handling Patterns
Comprehensive Error Handling
Retry Logic with Error Handling
Logging and Monitoring
Graceful Degradation
Best Practices
The
rawOutput property in structured output errors is useful for debugging
what the model actually generated.