dinod7
dinod7

Reputation: 61

Amazon Lex Error: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format

I'm trying to build a chatbot using Amazon's boto3 library. Right now, I am trying to create an intent using the put_intent function. My code is as follows:

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi?"]  
                              )

When I try running this, I get the following exception:

botocore.errorfactory.BadRequestException: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format: intent:test2:$LATEST

Can anyone tell me what I'm doing wrong?

Upvotes: 6

Views: 2308

Answers (4)

Stefan
Stefan

Reputation: 59

For the put_intent function I faced similar issues. At least the following 3 are worth mentioning.

  1. Sample Utterances

There are requirements for the sample utterances:

An utterance can consist only of Unicode characters, spaces, and valid punctuation marks. Valid punctuation marks are: periods for abbreviations, underscores, apostrophes, and hyphens. If there is a slot placeholder in your utterance, ensure that it's in the {slotName} format and has spaces at both ends.

It seems like there is no error raised when calling the put_intent function with the following code.

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi"]  
                              )

However, if you try to add it to your bot and start building the bot it will fail.

To fix it remove the question mark at the end of you sampleUtterance.

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi?"]  
                              )
  1. Prior intent version

If your intent already exists you need to add the checksum to your function call. To get the checksum of your intent you can use the get_intent function.

For example docs:

response = client.get_intent(
    name='test',
    version='$LATEST'
)
found_checksum = response.get('checksum')

After that you can put a new version of the intent:

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi"],
                              checksum = found_checksum
                              )
  1. Intent Name (correct in your case, just adding this for reference)

It seems like the name can only contain letters, underscores, and should be <=100 in length. Haven't found anything in the docs. This is just trial and error. Calling put_intent with the following:

intent = lexClient.put_intent(name = 'test_1',                                 
                              sampleUtterances = ["Who is messi"]  
                              )

Results in the following error:

BadRequestException: An error occurred (BadRequestException) when calling the PutIntent operation: RelativeId does not match Lex ARN format: intent:test_1:$LATEST

To fix the name you can replace it to:

intent = lexClient.put_intent(name = 'test',                                 
                              sampleUtterances = ["Who is messi"]  
                              )

Upvotes: 0

CloudSlayer
CloudSlayer

Reputation: 1

You need to run GetSlotType. That will return current checksum for that slot. Put that checksum in your PutSlotType checksum. Big bang boom.

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexModelBuildingService.html#getSlotType-property

var params = { name: "AppointmentTypeValue", checksum:'54c6ab5f-fe30-483a-a364-b76e32f6f05d',

description: "Type of dentist appointment to schedule'",
enumerationValues: [
    {
        value: "cleaning"
    },
    {
        value: "whitening"
    },
    {
        value: "root canal"
    },
    {
        value:"punch my face"
    }
]

};

Upvotes: 0

tishma
tishma

Reputation: 1885

I got the same error when trying to have a digit in intent name field. Realized that was not allowed when trying to do the same from AWS console.

Error handling could really be more specific.

Upvotes: 8

Dave Kerr
Dave Kerr

Reputation: 5297

Try taking the question mark out of the utterance, that has caused me issues in the past!

Upvotes: 3

Related Questions