Structured Output
The .GENStruct<T>() method generates JSON responses that are automatically mapped to strongly-typed C# classes.
Basic Usage
[JsonSchema]
public class Character
{
public string Name { get; set; }
public int Level { get; set; }
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}");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
Chat Completions - General text generation
Code Generation - Generate code
Responses API - Advanced features
Last updated