#Strict Mode JSON Generator Prompt 0.1
6 messages ยท Page 1 of 1 (latest)
{
"type": "object",
"properties": {
"score": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"description": "The score should be an integer between 0 and 100."
},
"message": {
"type": "string",
"not": {
"anyOf": [
{
"pattern": "NPC"
},
{
"pattern": "\\*"
}
]
},
"description": "The message is a string that should not contain the substring 'NPC' or any '*' characters."
}
},
"required": ["score", "message"],
"additionalProperties": false,
"description": "A JSON object that represents a score and a message."
}
here's an example responseJsonSchema with integrated descriptions, minimum and maximum constraints on a score integer, and a constraint to not mention the term "NPC" or include asterisks.
you can google "json schema dot org draft 07" for details on the standard format to specify json schemas and those plug in directly to validators you can apply to the responses from the AI LLMs.
This version of the prompt omits the code blocks from the instructions and from the example responses. That would make it less likely to get the ```json ``` backticks so this one's more suited for API calls since you won't have to deal with the code block stuff.
here's an example with four different schema categories and the requirement to categorize a given entity and generate valid json in the appropriate schema. tested and works in gpt-3.5-turbo so could be good for games and api settings or to save money or if you don't have gpt-4 access. example thread for your testing: https://chat.openai.com/share/f8c64f46-9157-4a32-b350-76b2db89d021
Good article on this topic:
Native JSON Output From GPT-4
SIMON FARSHID
JUN 14, 2023
On Substack
See also:
https://platform.openai.com/docs/guides/gpt/function-calling