ValidationException thrown when calling generation AI
Environment information
System:
OS: Windows 10 10.0.19045
CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
Memory: 31.27 GB / 47.93 GB
Binaries:
Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.21 - C:\Program Files\nodejs\yarn.CMD
npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.3.0 - C:\Program Files\nodejs\pnpm.CMD
NPM Packages:
@aws-amplify/auth-construct: 1.6.0
@aws-amplify/backend: 1.14.2
@aws-amplify/backend-ai: Not Found
@aws-amplify/backend-auth: 1.5.0
@aws-amplify/backend-cli: 1.4.12
@aws-amplify/backend-data: 1.4.0
@aws-amplify/backend-deployer: 1.1.19
@aws-amplify/backend-function: 1.12.2
@aws-amplify/backend-output-schemas: 1.4.0
@aws-amplify/backend-output-storage: 1.1.4
@aws-amplify/backend-secret: 1.1.6
@aws-amplify/backend-storage: 1.2.5
@aws-amplify/cli-core: 1.4.0
@aws-amplify/client-config: 1.5.7
@aws-amplify/data-construct: 1.15.1
@aws-amplify/data-schema: 1.19.0
@aws-amplify/deployed-backend-client: 1.5.1
@aws-amplify/form-generator: 1.0.4
@aws-amplify/model-generator: 1.0.12
@aws-amplify/platform-core: 1.6.4
@aws-amplify/plugin-types: 1.8.0
@aws-amplify/sandbox: 1.2.11
@aws-amplify/schema-generator: 1.2.7
aws-amplify: 6.13.6
aws-cdk: 2.1003.0
aws-cdk-lib: 2.183.0
typescript: 5.8.2
No AWS environment variables
No CDK environment variables
Describe the bug
After defining a generation AI in the data schema, when calling the AI using the useAIGeneration hook from createAIHooks(client), regardless of the input, I receive back the following error:
{ "data": { "summarize": null }, "errors": [ { "path": [ "summarize" ], "data": null, "errorType": "ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/", "errorInfo": null, "locations": [ { "line": 2, "column": 3, "sourceName": null } ], "message": "A custom error was thrown from a mapping template." } ] }
I cannot determine what is causing this error since there is no detail attached, I have followed the documentation.
Reproduction steps
- define schema in amplify/data/resource.ts
const schema = a.schema({
summarize: a
.generation({
aiModel: a.ai.model("Claude 3 Opus"),
systemPrompt:
"Summarize the following text:",
})
.arguments({
text: a.string().required(),
})
.returns(
a.customType({
summary: a.string(),
})
)
.authorization((allow) => [allow.publicApiKey()]),
});
-
run
npx ampx sandbox -
export client and useAIGeneration hook from client side file
"use client";
import { generateClient } from "aws-amplify/data";
import { Schema } from "@/amplify/data/resource";
import { createAIHooks } from "@aws-amplify/ui-react-ai";
export const client = generateClient<Schema>();
export const { useAIGeneration } = createAIHooks(client);
- In a client side component use the hook
export const someComponent = () => {
const [{ data, isLoading, hasError }, generateSummary] =
useAIGeneration("summarize");
return(
<>
<Button onClick={() => {
generateSummary({
text: "test",
});
}}
>
Generate Summary
</Button>
<div> {data.summary} </div>
</>
);
}
- go to dev tools and see that the request returns 200 but with ValidationException error from graphql
Hey,👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂
Hey @davidjulakidze, Thanks for reporting this issue! I suspect it might be related to an Authorization Mode Mismatch. Could you share the complete data/resource.ts file to help diagnose the problem?
@AnilMaktala
import { type ClientSchema, a, defineData } from "@aws-amplify/backend";
const schema = a.schema({
summarize: a
.generation({
aiModel: a.ai.model("Claude 3 Opus"),
systemPrompt:
"Summarize the following text:",
})
.arguments({
text: a.string().required(),
})
.returns(
a.customType({
summary: a.string(),
})
)
.authorization((allow) => [allow.publicApiKey()]),
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "apiKey",
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
},
});
Hey @davidjulakidze, Thanks for sharing the data/resource.ts file. I couldn't reproduce the issue with the provided details—I can see a response for the query. Which region is your app deployed in?
import { a, defineData, type ClientSchema } from "@aws-amplify/backend";
import { defineConversationHandlerFunction } from "@aws-amplify/backend-ai/conversation";
const schema = a.schema({
summarize: a
.generation({
aiModel: a.ai.model("Claude 3 Opus"),
systemPrompt: "Summarize the following text:",
})
.arguments({
text: a.string().required(),
})
.returns(
a.customType({
summary: a.string(),
})
)
.authorization((allow) => [allow.publicApiKey()]),
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "apiKey",
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
},
});
@AnilMaktala region is us-east-1
how do I get more information on why this error is happening?
Hey @davidjulakidze,Thanks for sharing the screenshot. It looks like Bedrock is returning this error. You can find more information in the CloudWatch logs by enabling monitoring on the AppSync settings page.
@AnilMaktala AppSync logs are showing the same generic error, how do I get more information as to why Bedrock is returning this error? there is no information showing up regarding this AI in Bedrock section of the console.
{
"logType": "ResponseFunctionEvaluation",
"path": [
"summarize"
],
"fieldName": "summarize",
"resolverArn": "arn:aws:appsync:us-east-1::apis//types/Query/resolvers/summarize",
"functionName": "QuerySummarizeDataResolverFn",
"requestId": "08af0ade-4cad-4fc7-a1ce-e0d9770435e3",
"fieldInError": true,
"errors": [
"CustomRuntimeException(message=A custom error was thrown from a mapping template., errorType=ValidationException:http://internal.amazon.com/coral/com.amazon.bedrock/, data=null, errorInfo=null)"
],
"parentType": "Query",
"graphQLAPIId": "",
"functionArn": "arn:aws:appsync:us-east-1::apis//functions/"
}
Hi @davidjulakidze can you confirm if you have enabled the model Claude 3 Opus in us-east-1 region in AWS Bedrock.
If you have not I am attaching the steps below to enable it.
Steps:
- AWS Bedrock console (Left sidebar) -> Bedrock Configurations -> Model Access
- Make sure that you are in the correct AWS region (i.e.
us-east-1in your case).
@tejas2008 @AnilMaktala Ok so I went inside Model Access, Claude 3 Opus said unavailable so I signed up for all of the other Anthropic models, was granted access, changed my backend generation AI model to Claude 3.5 Sonnet v2 and I'm still getting the same error. I even enabled bedrock logging, this is the error being returned from Bedrock:
{
"schemaType": "ModelInvocationLog",
"schemaVersion": "1.0",
"timestamp": "2025-03-29T06:30:00Z",
"accountId": "",
"identity": {
"arn": "arn:aws:sts:::assumed-role/GenerationBedrockDat/APPSYNC_ASSUME_ROLE"
},
"region": "us-east-1",
"requestId": "d2ecc510-0fde-4c60-8aa7-22a6198c09d5",
"operation": "Converse",
"modelId": "anthropic.claude-3-5-sonnet-20241022-v2:0",
"errorCode": "ValidationException"
}
same thing with Claude 3.5 Haiku
{
"schemaType": "ModelInvocationLog",
"schemaVersion": "1.0",
"timestamp": "2025-03-29T06:41:52Z",
"accountId": "",
"identity": {
"arn": "arn:aws:sts:::assumed-role/GenerationBedrockDat/APPSYNC_ASSUME_ROLE"
},
"region": "us-east-1",
"requestId": "5c825926-8953-47cb-8986-ed86a980c34e",
"operation": "Converse",
"modelId": "anthropic.claude-3-5-haiku-20241022-v1:0",
"errorCode": "ValidationException"
}
Hi @davidjulakidze ,
I am able to generate the summary for model Claude 3 Sonnet model in us-east-1 region. Below is the query output.
If possible you could try deleting the sandbox and create a new app with the corresponding model enabled in us-east-1 and using the below given schema.
import { type ClientSchema, a, defineData } from '@aws-amplify/backend';
const schema = a.schema({
summarize: a
.generation({
aiModel: a.ai.model("Claude 3 Sonnet"),
systemPrompt:
"Summarize the following text:",
})
.arguments({
text: a.string().required(),
})
.returns(
a.customType({
summary: a.string(),
})
)
.authorization((allow) => [allow.publicApiKey()]),
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({
schema,
authorizationModes: {
defaultAuthorizationMode: "apiKey",
apiKeyAuthorizationMode: {
expiresInDays: 30,
},
},
});
@AnilMaktala
Looks like models labeled as "Cross-region inference" on the Bedrock model access page are not functioning, while those without this label are working correctly.
Claude 3.5 Haiku
Claude 3.5 Sonnet
Hey @davidjulakidze, Cross-region inference is a known issue. Please try the suggested workaround provided here and let us know if it resolves your issue. https://github.com/aws-amplify/docs/issues/8121#issuecomment-2494375015
@AnilMaktala this workaround is for conversation, is there anything similar for generation?
Hey @davidjulakidze, Thank you for your patience. Unfortunately, there is no current workaround for generation. We’ve marked this as a feature request for the team to evaluate further.