githubEdit

brackets-curlyStructured Output

The .GENStruct<T>() method generates JSON responses that are automatically mapped to strongly-typed C# classes.

Basic Usage

[StrictJsonSchema("character", "A game character.")]
public class Character
{
    [JsonSchemaProperty("name", "Character name.", Required = true)]
    public string Name { get; set; }

    [JsonSchemaProperty("level", "Character level.", Required = true)]
    public int Level { get; set; }

    [JsonSchemaProperty("class", "Character class.", Required = true)]
    public string Class { get; set; }
}

Character hero = await "Generate a level 10 warrior"
    .GENStruct<Character>()
    .ExecuteAsync();

Debug.Log($"{hero.Name} - Lv.{hero.Level} {hero.Class}");

Note: [StrictJsonSchema] is required on the class. When Strict = true, all properties must have Required = true in their [JsonSchemaProperty].

Defining Schema Classes

1. Simple Class

2. Nested Objects

3. Collections

4. Enums

Input Types

String Input

Prompt Input

Configuration

Model Selection

Temperature

Common Use Cases

1. Data Extraction

2. Form Generation

3. Configuration Files

4. Content Generation

Unity Examples

Example 1: NPC Dialog Generator

Example 2: Item Database Generator

Example 3: Level Configuration

Example 4: Character Sheet

Best Practices

✅ Do

❌ Don't

Validation

Always validate generated data:

Provider Support

Provider
Support
Models

OpenAI

✅ Full

GPT-4o, GPT-4

Anthropic

✅ Full

Claude 3.5

Google Gemini

⚠️ Partial

Gemini 1.5 Pro

OpenRouter

✅ Varies

Model-dependent

Error Handling

Next Steps

Last updated