amplify-backend icon indicating copy to clipboard operation
amplify-backend copied to clipboard

AWS Amplify AI schema compilation fails when double quotes (") are embedded within systemPrompt or description string fields.

Open shivennn opened this issue 2 months ago • 1 comments

Environment information

npx ampx info
System:
  OS: macOS 15.6.1
  CPU: (10) arm64 Apple M4
  Memory: 179.58 MB / 16.00 GB
  Shell: /bin/bash
Binaries:
  Node: 20.19.0 - /usr/local/bin/node
  Yarn: 1.22.22 - /usr/local/bin/yarn
  npm: 11.4.2 - /usr/local/bin/npm
  pnpm: undefined - undefined
NPM Packages:
  @aws-amplify/auth-construct: 1.8.1
  @aws-amplify/backend: 1.16.1
  @aws-amplify/backend-ai: Not Found
  @aws-amplify/backend-auth: 1.7.1
  @aws-amplify/backend-cli: 1.8.0
  @aws-amplify/backend-data: 1.6.1
  @aws-amplify/backend-deployer: 2.1.3
  @aws-amplify/backend-function: 1.14.1
  @aws-amplify/backend-output-schemas: 1.7.0
  @aws-amplify/backend-output-storage: 1.3.1
  @aws-amplify/backend-secret: 1.4.0
  @aws-amplify/backend-storage: 1.4.1
  @aws-amplify/cli-core: 2.2.1
  @aws-amplify/client-config: 1.8.0
  @aws-amplify/data-construct: 1.16.3
  @aws-amplify/data-schema: 1.21.1
  @aws-amplify/deployed-backend-client: 1.8.0
  @aws-amplify/form-generator: 1.2.4
  @aws-amplify/model-generator: 1.2.0
  @aws-amplify/platform-core: 1.10.0
  @aws-amplify/plugin-types: 1.11.0
  @aws-amplify/sandbox: 2.1.2
  @aws-amplify/schema-generator: 1.4.0
  @aws-cdk/toolkit-lib: 1.1.1
  aws-amplify: Not Found
  aws-cdk-lib: 2.214.0
  typescript: 5.9.2
No AWS environment variables
No CDK environment variables

Describe the bug

When Amplify compiles the TypeScript schema to GraphQL, embedded double quotes in template literals cause GraphQL parsing errors because they're not properly escaped in the generated schema.

Schema

import { a } from "@aws-amplify/backend";

const problemSchema = a.schema({
  chat: a.conversation({
    aiModel: {
      resourcePath: 'us.anthropic.claude-3-haiku-20240307-v1:0',
    },
    systemPrompt: `This will break because of "double quotes" in the string.`,
    tools: [
      a.ai.dataTool({
        name: 'TestTool',
        description: 'This also breaks with "embedded quotes" in description.',
        model: a.ref('risk_spans'),
        modelOperation: 'list',
      }),
    ]
  }).authorization((allow) => allow.owner()),
});

export { problemSchema };

Error

6:14:37 PM [ERROR] [BackendBuildError] Unable to deploy due to CDK Assembly Error
  ∟ Caused by: [AssemblyError] Assembly builder failed
    ∟ Caused by: [InvalidSchemaError] Syntax Error: Expected ":", found Name "quotes".
      ∟ Caused by: [GraphQLError] Syntax Error: Expected ":", found Name "quotes".
    Resolution: Check your data schema definition for syntax and type errors.
Resolution: Check the Caused by error and fix any issues in your backend code

Solution

  • Used single quotes where emphasis was needed.
import { a } from "@aws-amplify/backend";

const fixedSchema = a.schema({
  chat: a.conversation({
    aiModel: {
      resourcePath: 'us.anthropic.claude-3-haiku-20240307-v1:0',
    },
    systemPrompt: `This works because of 'single quotes' in the string.`,
    tools: [
      a.ai.dataTool({
        name: 'TestTool',
        description: 'This also works with single quotes in description.',
        model: a.ref('risk_spans'),
        modelOperation: 'list',
      }),
    ]
  }).authorization((allow) => allow.owner()),
});

export { fixedSchema };

Reproduction steps

  • Try to deploy the above shared sample schema using npx ampx sandbox or using Amplify CI/CD.

shivennn avatar Sep 21 '25 12:09 shivennn