Alexa - Slots are being capitalized

amazon-alexa

#1

Found a weird bug, and I don’t think it is Jovo. I think the Alexa NLU is doing it. Normally, the slots are all stored as lowercase. Here’s an example from my logs:

"stainType": {
    "name": "stainType",
    "value": "red wine",
    "resolutions": {
        "resolutionsPerAuthority": [
            {
                "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.21c97416-c086-498c-a0a5-ea3bf4918ca5.xxxxxxxxx",
                "status": {
                    "code": "ER_SUCCESS_MATCH"
                },
                "values": [
                    {
                        "value": {
                            "name": "red wine",
                            "id": "07d4b2aa6a900c554874fa6d09b2243a"
                        }
                    }
                ]
            }
        ]
    },
    "confirmationStatus": "NONE",
    "source": "USER"
}

The ‘red wine’ slot works fine. But today I noticed my app wasn’t responding. I have another slot ‘mud’ that seems be capitalized. Also, it interpreted it as ‘Mudd’ - with the double-d on the end. I’ve added this weird spelling to the inputs just in case:

"stainType": {
    "name": "stainType",
    "alexaSkill": {
        "name": "stainType",
        "value": "Mudd",
        "resolutions": {
            "resolutionsPerAuthority": [
                {
                    "authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.21c97416-c086-498c-a0a5-ea3bf4918ca5.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                    "status": {
                        "code": "ER_SUCCESS_MATCH"
                    },
                    "values": [
                        {
                            "value": {
                                "name": "mud",
                                "id": "c95e3dd9ec9230450a558cb17be2106d"
                            }
                        }
                    ]
                }
            ]
        },
        "confirmationStatus": "NONE",
        "source": "USER"
    },
    "value": "Mudd",
    "key": "mud",
    "id": "c95e3dd9ec9230450a558cb17be2106d"
}

Strangely, from this it’s showing “ER_SUCCESS_MATCH” so it sees this as ‘mud’ anyway. But it messes up the app because I need that ‘mud’ value to process other things. All my inputs are lowercase in the en-GB.json model file:

{
    "value": "red wine",
},

Also here:

{
    "value": "mud",
        "synonyms": [
            "mudd",
            "dirt",
            "soil"
        ]
},

Any ideas why this might be happening?

Many thanks,

Simon


#2

Update: To provide a solution I just used this in my app, and it works well. Maybe this could help someone else having this issue:

let exampleSlot = this.$inputs.exampleSlot.value.toLowerCase();

But I’m still curious as to why the capitalization is happening?


#3

That is a pretty curious occurrence - but it represents an opportunity to remember that unless you format incoming data to suit your particular case exactly, something will always go sideways eventually.

I had an odd probably not too different that only happened while I was testing using textual inputs – turned out I should have been running a trim() on all inputs because there was a whitespace at the beginning of an input I’d been copying and pasting repeatedly.

Keep us posted on anything you find out about this.


#4

That’s very true, and I’m glad I’ve learned this lesson now rather than later when my app goes public. I guess we should always use methods like .toLowerCase or .trim() just in case. Funny what you mentioned - a similar thing happened to me the other day. I had a slot that wasn’t being recognised and I found out later I had an accidental whitespace at the end of the string. Sometimes, that’s all it takes to mess up everything!


#5

I’m not sure of the implications of applying toLowerCase() by default (in the framework). But, trim() would definitely make sense. What do you think?


#6

Hi @simon.revill and @nickmortensen, thanks for sharing your observations and thoughts on input normalization! I’m not sure whether this adds much to the discussion, but my hypothesis is that the Alexa NLU already capitalizes some proper names like those of brands, like in this case (Mudd is a brand of jeans).


#7

Hi @Florian and @AlexSwe. Just to clarify: I only used the .toLowerCase() method to copy and save the input value to a variable. I’m not trying to change the raw input. This is because, as part of my app, I need to extract the value of the slot from the user input to match and collect data I have in a separate JSON file.

@Florian, thank you for your hypothesis. I’m glad you mentioned ‘Mudd’. I didn’t know that was a brand! I was puzzled by this and now that makes complete sense. I also have a slot ‘thai’ that Amazon adjusts to ‘Thai’, so the same is true for countries as well as brands.