amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

ValidationException thrown when calling generation AI

Open davidjulakidze opened this issue 7 months ago • 7 comments

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

  1. 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()]),
});
  1. run npx ampx sandbox

  2. 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);
  1. 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>
  </>
);
}
  1. go to dev tools and see that the request returns 200 but with ValidationException error from graphql

davidjulakidze avatar Mar 24 '25 22:03 davidjulakidze