Define structured data types for AI inputs and outputs
Classes define structured data types that can be used as function inputs, outputs, or nested within other types. In the context of LLMs, classes describe the shape of data you inject into prompts and extract from responses.
Classes can reference other classes (including recursively):
class Company { name string employees Person[] headquarters Address}class Address { street string city string country string}class Person { name string manager Person? // Recursive reference}
Adds context to the field in the prompt, helping the LLM understand what to extract.
class Person { name string @description("The person's full legal name") age int? @description("Age in years, if mentioned") occupation string @description("Current job title or profession")}
class Document { summary string @description(#" A concise summary of the document in 2-3 sentences. Focus on the main points and key takeaways. "#) metadata Metadata @description(#" Structured metadata including: - Author information - Publication date - Document type "#)}
enum Priority { Low Medium High Critical}enum TicketStatus { Open InProgress @alias("in_progress") Resolved Closed}class Ticket { id string title string description string priority Priority status TicketStatus created_by Person assigned_to Person? tags string[] attachments Attachment[]}class Attachment { filename string file_type string url string}class Person { name string email string role string?}
class Organization { name string departments Department[] headquarters Address}class Department { name string @description("Department name") manager Employee employees Employee[] sub_departments Department[] // Recursive}class Employee { id string name string email string title string reports_to Employee? // Recursive reference}class Address { street string city string state string? country string postal_code string}
// ✗ Not supported// class Employee extends Person { }// ✓ Use composition insteadclass Employee { person Person employee_id string department string}class Person { name string email string}