JSON mode not returning valid JSON

I’ll offer you an alternative approach (mentioned here) you can explore.

disclaimer: I feel like jsonmode, functions, assistants, and all that stuff are gimmicks. but that’s just my current personal opinion

this works well with gpt-3.5-turbo-instruct:

Here’s a short story. Could you kindly create a description of the story as a JSON object?
-----------

Once upon a time in a small village, there were ten unique individuals. There was Amelia, the talented artist, always seen with a sketchpad in her hand. Next was Benjamin, the curious scientist, constantly conducting experiments in his backyard. Clara, the kind-hearted nurse, spent her days tending to the ill and the injured. Darren, the mischievous trickster, always had a prank up his sleeve. Eliza, the aspiring chef, could be found in her kitchen, concocting delicious recipes. Fred, the wise old man, spent his time under his favorite tree, sharing stories with anyone who would listen. Grace, the passionate teacher, inspired her students with her energetic lessons. Harry, the adventurous explorer, was always venturing into the unknown, seeking new discoveries. Isabella, the gentle gardener, nurtured her magnificent botanical creations. Lastly, Jackson, the compassionate volunteer, dedicated his time to helping those less fortunate. These ten individuals, though different in their pursuits, shared a common love for their village and one another. Their unique talents and selflessness came together, creating a harmonious community that thrived, celebrated, and most importantly, lived happily ever after.

---------
schema:

{
    Characters: {
        character_name: {
            Appearance: description,
            Personality: description,
            Relationships: description
    },
    Settings: {
        location_name: {
            Appearance: description,
            Location relative to other places: description,
            Familiarity to the narrator: description
        }
    }
}

--------
JSON:

{   

generation

 
   "Characters":{ 
      "Amelia":{ 
         "Appearance":"Always seen with a sketchpad in her hand.",
         "Personality":"Talented artist",
         "Relationships":"Loved her village and the other villagers"
      },
      "Benjamin":{ 
         "Appearance":"Constantly conducting experiments in his backyard.",
         "Personality":"Curious scientist",
         "Relationships":"Respected by the other villagers for his knowledge and discoveries"
      },
      "Clara":{ 
         "Appearance":"Spent her days tending to the ill and injured.",
         "Personality":"Kind-hearted nurse",
         "Relationships":"Cared for everyone in the village, especially the sick and injured"
      },
      "Darren":{ 
         "Appearance":"Always had a prank up his sleeve.",
         "Personality":"Mischievous trickster",
         "Relationships":"Brought laughter and joy to the village with his tricks, loved by all"
      },
      "Eliza":{ 
         "Appearance":"Could be found in her kitchen, concocting delicious recipes.",
         "Personality":"Aspiring chef",
         "Relationships":"Cooked for the whole village, always sharing her love for food"
      },
      "Fred":{ 
         "Appearance":"Spent his time under his favorite tree, sharing stories with anyone who would listen.",
         "Personality":"Wise old man",
         "Relationships":"Mentored the younger villagers with his wisdom, loved by all"
      },
      "Grace":{ 
         "Appearance":"Inspired her students with her energetic lessons.",
         "Personality":"Passionate teacher",
         "Relationships":"Known and loved by all the village children for her inspiring teaching methods"
      },
      "Harry":{ 
         "Appearance":"Always venturing into the unknown, seeking new discoveries.",
         "Personality":"Adventurous explorer",
         "Relationships":"Admired by the other villagers for his bravery and determination"
      },
      "Isabella":{ 
         "Appearance":"Nurtured her magnificent botanical creations.",
         "Personality":"Gentle gardener",
         "Relationships":"Loved by the villagers for her beautiful gardens and kind nature"
      },
      "Jackson":{ 
         "Appearance":"Dedicated his time to helping those less fortunate.",
         "Personality":"Compassionate volunteer",
         "Relationships":"Respected and appreciated by the villagers for his selfless acts of kindness"
      }
   },
   "Settings":{ 
      "Small Village":{ 
         "Appearance":"A quaint and peaceful village, surrounded by lush greenery and fields.",
         "Location relative to other places":"Located in a secluded area, far from any bustling cities.",
         "Familiarity to the narrator":"The villagers were like family to each other, living and working together harmoniously."
      }
   }
}

just prepend a { to the generation and you have a valid json. I haven’t had an issue with this so far if the schema’s fairly simple. I’ve been using this method since davinci-002 came out.

Sometimes the text is too difficult to understand and you may need preprocessing steps/chunking or use gpt-4