I have had a couple of clients send in questions about solving this problem. After creating a Google Assistant integration, when you try to save your intents, Dialogflow cancels the save and shows a popup error at the bottom which reads like this:
There are usually three parts to this error.
1 "Request contains an invalid argument"
2 "The query pattern () contains an undefined parameter"
3 The actual query inside the quotes will usually have $SchemaOrg_datatype embedded in it somewhere.
Here is another example of this pattern from a StackOverflow question.
What causes the error
I don't know exactly what causes this error, but I will point you to a few resources which might help you come to your own conclusions, as well as possibly help you debug the issue.
As you know, the 1-click Google Assistant integration uses the Actions SDK behind the scenes to enable the integration. First, read this article on the difference between Actions SDK vs Dialogflow. By itself, Actions SDK doesn't have its own Natural Language Understanding (NLU) component. Dialogflow is the service which provides the NLU when you create an Assistant app from within Dialogflow.
But it is also possible to create an Assistant app using just the Actions SDK (you need the user's phrases to exactly match the query pattern you provide). Notice, for example, that the docs mention how you can build assistant apps using either Dialogflow or Actions SDK.
Usually, you create an actions.json "package" file to specify the behavior of such an app. You can read the overview at the link I just provided, and you will see that you need to define actions using a JSON file.
How to define parameters?
The next question, if you were to simply define various iterations of user phrases in the specification of your actions.json file, is - how can you define parameters? You certainly don't want to list a single phrase per parameter value (say, you are trying to define a city name).
A solution that the Actions SDK provides for this is to use Schema.org - which is an open standard which allows you to define datatypes for structured data.
A sample action JSON file looks like this:
Notice the following;
- you can use Schema.org types to give hints so the Actions SDK can match the user's phrase with an intent
- you embed the schema.org datatype using the appropriate syntax directly into the queryPattern field
- also notice that the syntax looks like this - $datatype:variableName
So inside the queryPatterns array you can say something like
"find some $org.schema.type.Color:color sneakers"
In the above phrase, the standard schema.org datatype is org.schema.type.Color and the variable name is color (all lower case).
$org.schema.type vs $SchemaOrg_
We are getting closer to understanding what is going on, but you would have noticed that the error uses the prefix $SchemaOrg_ while the actions JSON file uses the prefix $org.schema.type.
Initially, I too was thrown off by this difference, and did a bit more research. Apparently, this change happened when actions package moved from v1 to v2.
How to fix the error
So, with all this information at our disposal, we can now start making changes to the agent to fix the error (remembering that we still don't know exactly why this error happens).
The one thing which is common to all solutions I have provided myself, as well as found online, is to delete the offending training phrase. One way to do this is to simply delete all training phrases from all intents and re-add them one by one to see where the problem happened. Something tells me you wouldn't be interested in a solution like that. 🙂
Now, it is very important to understand something. You will not find the parameter placeholder (e.g. $SchemaOrg_ or $org.schema.type) in any of the training phrases or their underlying query patterns. This is the "missing piece" in understanding the error, of course, because Dialogflow/Google Asssistant adds the translation of your [ Dialogflow training phrase => Actions package query pattern ] in the background.
So your goal is quite simple: carefully observe the error message and extract out the relevant bits which will help you to get to the offending training phrase. Let us take the following example that I started with at the beginning of this article:
The query pattern
'I don&#$SchemaOrg_Number:number;t have friends on Skype'
contains an undefined parameter (name:'number' type:'SchemaOrg_Number')
When you remove the query parameter (highlighted in red), you are left with
'I don&#;t have friends on Skype'
Also, the undefined parameter has the name 'number' and type 'SchemaOrg_Number'.
So you should search across your intents for the phrase 'friends on Skype' and delete that training phrase.
But what if you don't want to delete the offending training phrase?
In some cases, it is pretty obvious that you just need to update the offending intent to re-add it properly.
For example, in my client's case, we figured out that the problem was caused by automatically adding a training phrase via the "Training" feature in Dialogflow. As it turns out, when Skype and Dialogflow APIs talk to each other in the 1-click Skype integration, something gets messed up in the encoding and Dialogflow receives the training phrase with a bunch of escape characters (&) and such. So we found the offending training phrase, it contained some junk characters, and we removed it and replaced it with the regular training phrase by removing the superfluous escape characters which were messing up the training phrase.
In other words, most likely your error is caused by some special characters getting added to your training phrase without your knowledge. For example, one of the answers under the StackOverflow question I linked to says this:
For whatever its worth, I don't think characters like apostrophes and hyphens automatically cause issues if they are typed directly into the Dialogflow console since I have tried that and I haven't seen any errors. For now, I think it is quite likely due to copy/paste from some website which is causing some kind of encoding issue in your training phrase.
So if you want to keep the training phrase, my suggestion is to simply delete the training phrase, and re-add it by typing it directly into the Dialogflow console. That will likely get rid of the encoding issue.
Have you faced this issue? How did you resolve it?