Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Groq Groq python ErrorObject Type

From Leeroopedia
Knowledge Sources
Domains Error_Handling, Type_System
Last Updated 2026-02-15 16:00 GMT

Overview

Concrete tool for representing structured API error responses provided by the Groq Python SDK's shared type system.

Description

The ErrorObject class is a Pydantic BaseModel that represents the structured error body returned by the Groq API when a request fails. It contains the error message, type, and optional code, along with schema validation details (schema_code, schema_kind, schema_path, schema_path_segments) for JSON schema errors, failed_generation for content that failed validation, and a Debug sub-model with token-level information when debug mode is enabled.

Usage

ErrorObject appears within exception responses from the Groq API. When catching APIStatusError exceptions, the response body is parsed into this type. The debug field is populated only when requests include debug=true.

Code Reference

Source Location

Signature

class Debug(BaseModel):
    """Debug information including input and output token IDs and strings."""
    input_token_ids: Optional[List[int]] = None
    input_tokens: Optional[List[str]] = None
    output_token_ids: Optional[List[int]] = None
    output_tokens: Optional[List[str]] = None


class ErrorObject(BaseModel):
    message: str
    type: str
    code: Optional[str] = None
    debug: Optional[Debug] = None
    failed_generation: Optional[str] = None
    param: Optional[str] = None
    schema_code: Optional[str] = None
    schema_kind: Optional[str] = None
    schema_path: Optional[str] = None
    schema_path_segments: Optional[List[str]] = None

Import

from groq.types.shared import ErrorObject

I/O Contract

ErrorObject Fields

Name Type Required Description
message str Yes Human-readable error message
type str Yes Error type identifier (e.g. "invalid_request_error")
code Optional[str] No Machine-readable error code
debug Optional[Debug] No Token-level debug info (only when debug=true)
failed_generation Optional[str] No Content that failed schema validation
param Optional[str] No Parameter that caused the error
schema_code Optional[str] No Schema validation error code
schema_kind Optional[str] No Schema validation kind
schema_path Optional[str] No Path within the schema where validation failed
schema_path_segments Optional[List[str]] No Segments of the schema path

Debug Fields

Name Type Required Description
input_token_ids Optional[List[int]] No Token IDs for the input
input_tokens Optional[List[str]] No Token strings for the input
output_token_ids Optional[List[int]] No Token IDs for the output
output_tokens Optional[List[str]] No Token strings for the output

Usage Examples

Handling API Errors

from groq import Groq, APIStatusError

client = Groq()

try:
    completion = client.chat.completions.create(
        model="nonexistent-model",
        messages=[{"role": "user", "content": "Hello"}],
    )
except APIStatusError as e:
    error = e.body
    if error:
        print(f"Error type: {error.get('type')}")
        print(f"Message: {error.get('message')}")
        if error.get('code'):
            print(f"Code: {error['code']}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment