Lesson 2 of 4 Troubleshooting GenAI Applications

Diagnosing Foundation Model API Integration Errors

This lesson catalogues the small number of causes behind integration errors with generative AI services and how error logging, request validation and response analysis reveal them quickly.

Learning outcomes

After completing this lesson, you will be able to:

  • Map error codes to their causes.
  • Log errors with enough context to diagnose them.
  • Analyze responses to find integration problems.

Error codes and their causes

ValidationException (HTTP 400) means the request is invalid: malformed JSON, missing required fields, unsupported parameters for the model, wrong content block types, messages that do not alternate roles or start with a user turn, tool results without matching tool use IDs, input above the context window, or calling a model on demand that requires an inference profile. AccessDeniedException (403) means missing IAM permissions (for example InvokeModelWithResponseStream for streaming), a denying SCP or permissions boundary, a guardrail condition key not satisfied, or a model not available to the account in that Region. ResourceNotFoundException (404) indicates a wrong model ID, ARN or Region.

ThrottlingException (429) means quota exceeded; ModelTimeoutException means generation took too long; ServiceUnavailableException (503) and InternalServerException (500) are transient; ModelNotReadyException means an imported model is starting; ModelErrorException indicates an error in the model's processing of the request.

The following diagram compares the configuration that failed after a model switch with the corrected one that uses a cross-Region inference profile.

Fixing errors after a model switch. The newer model is offered on demand only through a cross-Region inference profile, so calls with its base model ID fail with a ValidationException. Configuring the profile ID and granting IAM permissions on the profile and on the model in the destination Regions fixes it.
The Regions in the profile must also be allowed by any service control policy.
Match the pairs

Bedrock errors and causes

Exam skills 5.2.2

Match each Amazon Bedrock error with its usual cause.

Log in to try this activity Interactive activities are free with an account.

Error logging, request validation and response analysis

Error logging records, for every failure, the error code and message, the AWS request ID, model ID, operation, Region, input token estimate and the caller, in structured logs that Logs Insights can group by error type. Request validation before calling, for example against a schema for the Converse message structure and a token budget, turns many runtime validation errors into immediate, clear application errors. Response analysis checks every successful response: the stop reason (end_turn, max_tokens, tool_use, stop_sequence, guardrail_intervened, content_filtered), empty content, unexpected formats and token usage.

The following table summarises common integration problems.

SymptomLikely causeFix
ValidationException after adding historyRoles not alternating or bad tool result IDsValidate message structure
ValidationException for a new model IDModel requires an inference profileUse the inference profile ID or ARN
AccessDeniedException only when streamingMissing InvokeModelWithResponseStreamAdd the permission
AccessDeniedException with cross-Region profileDestination Region permissions or SCPAllow profile and models in all profile Regions
Intermittent 429 at peaksQuota exceededBackoff, queues, cross-Region inference, quota increase
Responses replaced by a fixed messageGuardrail intervenedInspect guardrail trace; adjust policy or input
Select all that apply

What to log for each failure

Exam skills 5.2.2

Choose the fields a structured error log should record for each failed model call.

Log in to try this activity Interactive activities are free with an account.
Worked example

Errors after a model switch

After changing the configured model ID to a newer model, every request fails with ValidationException stating that on-demand throughput is not supported for this model.

The newer model is offered on demand only through a cross-Region inference profile. Updating the configuration to the profile ID (for example with the us. or eu. prefix) and granting IAM permissions on the profile and the model in the profile's Regions fixes the integration.

Check yourself

An AccessDeniedException occurs although the IAM policy allows InvokeModel. What else can deny it?

Show answer

An SCP, a guardrail condition in a policy, or the model not being available to the account.

Exam Tips

Remember for the exam

  • ValidationException: fix the request (structure, parameters, length, inference profile).
  • AccessDeniedException: IAM, SCPs, guardrail conditions or model availability.
  • Retry 429 and 5xx with backoff; never retry 4xx validation errors unchanged.
  • Check stop reasons, including guardrail interventions, on every response.