Enums with 'other' for Extensibility
Add an 'other' value plus a detail field.
Enums with 'other' for Extensibility is a free Claude Architect lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Claude Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Problem with a Closed Enum
Enums are the backbone of clean structured output. When you constrain a field to a fixed set of values — like category being one of billing, technical, or account — the model can't drift into free-form strings, and downstream code can branch with confidence.
But a closed enum has a hidden failure mode: the real world produces inputs your list never anticipated. When a ticket doesn't fit any allowed value, the model is forced to pick the least wrong option. That's a silent misclassification, and it corrupts everything built on top of it.
The Extensibility Pattern: 'other' + detail
The architect-grade fix is the extensibility pattern: add an "other" value to the enum, plus a free-text detail field the model fills in when it selects other.
This gives you two wins at once:
- The model has an honest escape hatch instead of a forced bad fit.
- You capture what the unexpected case actually was — raw signal you can mine to grow the enum later.
It turns the gap in your taxonomy into a logged, inspectable data point instead of a corrupted record.
A Schema with 'other'
Here is a classification tool for a support agent. Notice the enum includes "other", and there's a companion category_detail string for the open case.
Because structured output via tool_use + JSON Schema enforces the enum, the model literally cannot return a value outside the list — including the deliberate other safety valve.
classify_ticket = {
"name": "classify_ticket",
"description": "Classify a support ticket into one category.",
"input_schema": {
"type": "object",
"properties": {
"category": {
"type": "string",
"enum": ["billing", "technical", "account", "other"],
"description": "Use 'other' ONLY when none of the named categories fit."
},
"category_detail": {
"type": "string",
"description": "Required when category is 'other': a short phrase naming the real category."
}
},
"required": ["category"]
}
}Why detail Must NOT Be Required
The most important schema decision here: mark category_detail as optional, never required.
A core structured-output rule is to require a field only if it is always present. The detail field is present only when category is other — it is absent for billing, technical, and account tickets.
If you force it into required, the model will fabricate a detail string for cases that don't need one, just to satisfy the schema. You'd be manufacturing hallucinations to enforce a rule you didn't actually need.
Conditional Requirement Lives in the Prompt
So how do you make sure category_detail is filled when the model picks other? The dependency is conditional, so it belongs in the field description and the system prompt — not in the schema's static required array.
Be explicit about the rule. Explicit criteria beat vague instructions every time.
system = (
"Classify each ticket using the classify_ticket tool.\n"
"Pick the most specific named category that fits.\n"
"Choose 'other' ONLY when no named category applies. "
"When you choose 'other', you MUST also provide category_detail "
"as a short noun phrase naming the true category "
"(e.g. 'partnership inquiry', 'legal request')."
)Forcing Structured Output with tool_choice
To guarantee the model returns the classification as structured data rather than prose, force the tool call. Setting tool_choice to {"type": "tool", "name": "classify_ticket"} compels Claude to emit exactly that tool's input, schema-validated.
If you had several extraction tools and just wanted to guarantee some structured call, tool_choice: "any" would do; "auto" lets the model choose between text and a tool. For a single forced schema, name the tool explicitly.
resp = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=512,
system=system,
tools=[classify_ticket],
tool_choice={"type": "tool", "name": "classify_ticket"},
messages=[{"role": "user", "content": ticket_text}],
)Reading the Result Safely
On the consuming side, branch on the enum. The other bucket is where you read category_detail — and where you should expect it to sometimes be missing, because it's optional.
Defensive access (a default of empty string) keeps your code robust against a legitimately absent field, which is exactly the behavior you designed for.
block = next(b for b in resp.content if b.type == "tool_use")
result = block.input
category = result["category"]
if category == "other":
detail = result.get("category_detail", "")
log_uncategorized(ticket_text, detail) # capture for later enum growth
else:
route_to_queue(category)Mining 'other' to Grow the Enum
The detail field isn't just a fallback — it's a feedback loop. Every other record carries a human-readable label for a case your taxonomy missed.
Periodically aggregate those details. When a cluster like "partnership inquiry" shows up 40 times a week, you've found your next first-class enum value. You promote it from free text to a named category, and your classifier gets sharper — driven by real data, not guesswork.
Pairs Naturally with Retry-with-Feedback
This pattern composes cleanly with validation. If a result violates your conditional rule — say category is other but category_detail came back empty — that's a structural error, and retry-with-feedback fixes exactly those.
Send the model the original ticket, its own wrong output, and the precise validation error. Crucially, retry helps because the information needed (the real category) is present in the source. Retry would not help if the information were simply absent from the ticket.
if result["category"] == "other" and not result.get("category_detail"):
feedback = (
"You returned category='other' but left category_detail empty. "
"Re-classify and provide a short detail phrase."
)
# resend: original ticket + the bad output + this exact errorWhen NOT to Add 'other'
The pattern is for extensibility under uncertainty — open-world taxonomies like ticket categories, document types, or intent labels where new cases will keep appearing.
Don't bolt other onto a genuinely closed set. A priority field of low / medium / high is exhaustive by definition; an other there just invites the model to dodge a real decision. Reserve the escape hatch for enums that legitimately can't anticipate every value.
The Full Pattern in One View
Put the pieces together and you have a small, robust contract:
- Enum with named values plus
other— the schema enforces the closed set. - Optional detail field — never required, so the model won't fabricate it.
- Prompt + description carry the conditional "fill detail when other" rule.
- Consumer branches on the enum and logs the detail.
- Validation/retry catches a missing-but-required-by-rule detail.
It's a clean separation: the schema guarantees shape; the prompt guarantees behavior; the loop captures what you didn't foresee.
Quick Check: Designing the 'other' Field
You're building a ticket-classifier tool whose category enum includes billing, technical, account, and other. You add a category_detail string that should be populated whenever the model picks other. How should you encode the requirement that category_detail be filled for other cases?
Recap: Extensible Enums
Key takeaways:
- Closed enums silently misclassify inputs they never anticipated; an
othervalue gives the model an honest escape hatch. - Pair
otherwith a free-text detail field to capture what the unexpected case actually was. - Keep the detail field optional — never require a field that may be absent, or the model will fabricate it.
- Put the conditional "fill detail when other" rule in the prompt and field description, not the static
requiredarray. - Mine logged
otherdetails to grow the enum with real first-class values over time. - Use
tool_use+ JSON Schema to enforce the enum, and retry-with-feedback for structural violations.
Frequently asked questions
Is the “Enums with 'other' for Extensibility” lesson free?
Yes — the full text of “Enums with 'other' for Extensibility” is free to read here on the web, and the Claude Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Claude Architect course, upgrade to CoddyKit PRO.
What will I learn in “Enums with 'other' for Extensibility”?
Add an 'other' value plus a detail field. You practise Claude Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Claude Architect?
No prior experience is required. Claude Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Enums with 'other' for Extensibility” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Claude Architect lesson?
Yes. Every Claude Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- tool_use for Guaranteed Structure
- Designing a JSON Schema
- Required vs Optional/Nullable Fields
- Enums with 'other' for Extensibility