Skip to content

Errors

All SDK errors extend FoundationModelsError. Import specific error classes to handle them individually.

Hierarchy

FoundationModelsError
├── GenerationError
│   ├── ExceededContextWindowSizeError
│   ├── AssetsUnavailableError
│   ├── GuardrailViolationError
│   ├── UnsupportedGuideError
│   ├── UnsupportedLanguageOrLocaleError
│   ├── DecodingFailureError
│   ├── RateLimitedError
│   ├── ConcurrentRequestsError
│   ├── RefusalError
│   └── InvalidGenerationSchemaError
└── ToolCallError

Error Reference

ErrorCodeWhen
ExceededContextWindowSizeError1Session history too long
AssetsUnavailableError2Model not downloaded
GuardrailViolationError3Content policy violation
UnsupportedGuideError4Unsupported generation guide
UnsupportedLanguageOrLocaleError5Language not supported
DecodingFailureError6Structured output parse failure
RateLimitedError7Too many requests
ConcurrentRequestsError8Session already responding
RefusalError9Model declined to answer
InvalidGenerationSchemaError10Malformed schema
ToolCallErrorTool's call() threw

GenerationErrorCode

Enum mapping status codes to error types:

ts
enum GenerationErrorCode {
  SUCCESS = 0,
  EXCEEDED_CONTEXT_WINDOW_SIZE = 1,
  ASSETS_UNAVAILABLE = 2,
  GUARDRAIL_VIOLATION = 3,
  UNSUPPORTED_GUIDE = 4,
  UNSUPPORTED_LANGUAGE_OR_LOCALE = 5,
  DECODING_FAILURE = 6,
  RATE_LIMITED = 7,
  CONCURRENT_REQUESTS = 8,
  REFUSAL = 9,
  INVALID_SCHEMA = 10,
  UNKNOWN_ERROR = 255,
}

Usage

ts
import {
  FoundationModelsError,
  GenerationError,
  ExceededContextWindowSizeError,
  GuardrailViolationError,
  ToolCallError,
} from "tsfm-sdk";

try {
  await session.respond("...");
} catch (e) {
  if (e instanceof ToolCallError) {
    // Tool handler threw
  } else if (e instanceof GenerationError) {
    // Any generation error
  } else if (e instanceof FoundationModelsError) {
    // Any SDK error
  }
}

Released under the Apache 2.0 License.