It’s essential for your schema to have descriptions for each property, or the model has no way of knowing what to map to those fields. You can (and should) also then instruct it via the prompt. We do it via System Instructions, but that’s essentially just pre-context. Here’s an example from one of our projects:
const pageItemSchema = {
type: Type.OBJECT,
description: "Schema for a single page.", // Optional
properties: {
pageNumber: {
type: Type.NUMBER,
description: "The page number"
},
pageType: {
type: Type.STRING,
description: "The type of page",
enum: [
"cover", "image", "story", "gameplay", "characters",
"locations", "weapons", "collectibles", "style"
]
},
pageMeta: {
type: Type.STRING,
description: "Additional non-displayed meta information about the page"
},
pageTitle: {
type: Type.STRING,
description: "The page title"
},
pageContent: {
type: Type.STRING,
description: "The full content for this page, in markdown format"
}
},
required: ["pageNumber", "pageType", "pageMeta", "pageTitle", "pageContent"]
};
and here is a small snippet from our System Instructions:
- Once they pick an idea, use your knowledge to create the game concept.
- You will return your idea to the user as a series of 'pages' which go together to form a game design document.
- Use the 'message' field of the responseSchema to ask the user to check over your idea.
- Tell them they can ask you to change anything they don't like.
- If the user says "Think of an idea for me - regarding page ..." go to step 8.
- Use the 'pages' responseSchema array with the following:
* pageNumber: The page number, starting at 1 and incrementing for each page.
* pageType: The type of page. This must be exactly one of the following enums:
- cover
- image
- story
- gameplay
- missions
- characters
- vehicles
- locations
- weapons
- collectibles
- style
* pageMeta: Additional non-displayed meta information about the page.
* pageTitle: The title of the page. If the pageType is 'cover' this should be the game title.
* pageContent: The full content for this page in markdown format. Never repeat the pageTitle in the pageContent. Only add an h2 if it's different to the pageTitle.
You can instruct it what goes where, and how - and you should. As it cannot figure it out for itself. But it does mean you get fully formed output back again and don’t have to then parse it yourself.
Remember: What comes back will still always just be text. It will follow your structure, but you must do things like parseInt()
for example to convert those types. The API doesn’t do that for you (at least not for TypeScript).