Single-Label Classification
Define a backed enum for the possible labels and a response model that holds the prediction.Multi-Label Classification
When a single input can belong to several categories at once, use a typed array of enums.Tips for Better Classification
Always include a fallback option
Adding anOTHER or UNKNOWN case gives the model an escape hatch when the input does not fit
neatly into your predefined categories. Without it, the model is forced to pick an incorrect label.
Use descriptive enum values
The string values of your enum cases are included in the JSON Schema that the model receives. Descriptive values liketech_issue communicate intent better than opaque codes like T1.
Add PHPDoc descriptions
You can annotate enum cases or the response model properties with PHPDoc comments to give the model additional guidance.Keep the schema narrow
Classification quality improves when the model has fewer valid shapes to choose from. If your response model only needs a label, do not add extra fields. If you need confidence scores or explanations, add them as separate properties so the model can fill them independently.Validate with custom rules
For multi-label classification, you may want to enforce constraints like “at least one label” or “no more than three labels”. Use theValidationMixin trait or implement CanValidateSelf to
add custom validation logic that Instructor will enforce automatically.