Common Issues
Common IssuesCould not JSON-decode the response from AI service

Could not JSON-decode the response from AI service

Gato AI Translations for Polylang sends a prompt to the AI service, and the response is in JSON format.

Depending on the data that you send (strings to translate, and language), the AI service might produce a response that is not valid JSON. The logs will show an error message like this:

Error [Query "translate-customposts"] Execution with errors: 🔴 Translation to zh_CN failed - There was an error requesting data from the API for provider 'OpenRouter': Could not JSON-decode the OpenRouter API's 'choices[0].message.content' field in the response

Whenever we discover a new issue, we tweak the prompt to prevent it from happening again.

Currently, the prompt contains the following:

If a sentence contains HTML, only translate the following properties inside the HTML tags: alt, title, placeholder, aria-label, aria-describedby, aria-labelledby, aria-placeholder.
Keep emojis exactly as they are, do not translate them.
Ensure that any double quotes (") within a translated string are properly escaped by adding a backslash before them (\"), but only if they haven't been escaped already.
Ensure that slashes within HTML tags are not escaped.
Ensure that the response is encoded using UTF-8 for all characters.

If you get an error, then it's a new issue that we need to identify and fix.

Do the following:

Once it works, send us your prompt, and we will hardcode that solution within the plugin.