🎯 Key Insight
Enums can contain ANY values you need - not just predefined options like gender. Use them for status codes, roles, categories, ratings, sizes, currencies, and any categorical data!
Enum Syntax
field_name:e(value1,value2,value3,...)
Rules
- Maximum 10 values per enum field
- Exact match only - case-sensitive
- No whitespace around commas (unless intentional)
- Any characters allowed except
,and() - Empty values not permitted in definition
Common Enum Patterns
🔄 Workflow Status
Track items through a workflow pipeline:
# Order processing order_status:e(pending,confirmed,processing,shipped,delivered,cancelled) # Document workflow doc_status:e(draft,review,approved,published,archived) # Task management task_status:e(todo,in_progress,review,blocked,done) # Payment processing payment_status:e(pending,processing,completed,failed,refunded) # Support tickets ticket_status:e(open,assigned,in_progress,resolved,closed)
👤 Roles & Permissions
User roles for access control:
# Basic roles role:e(admin,user,guest) # Extended roles role:e(super,admin,moderator,user,guest,viewer) # API scopes (DTLAuth) scope:e(read,write,admin,delete,none) # Account types account_type:e(personal,business,enterprise,trial)
⚡ Priority Levels
# Standard priority priority:e(low,medium,high,critical) # Extended priority priority:e(lowest,low,medium,high,highest,urgent) # Severity levels severity:e(info,warning,error,critical,fatal) # Log levels level:e(debug,info,warn,error,fatal)
💰 Finance & Currency
# Major currencies currency:e(USD,EUR,GBP,AED,JPY,CNY,INR,SAR) # Transaction types tx_type:e(deposit,withdrawal,transfer,payment,refund) # Account types account:e(savings,checking,investment,loan,credit) # Payment methods payment_method:e(card,bank,wallet,crypto,cash)
🏥 Healthcare
# Gender gender:e(M,F,O) # Blood types blood_type:e(A+,A-,B+,B-,AB+,AB-,O+,O-) # CTAS triage levels ctas:e(1,2,3,4,5) # Medication frequency frequency:e(once,daily,bid,tid,qid,prn,weekly) # Patient status patient_status:e(active,inactive,deceased,transferred)
🛒 E-Commerce
# Product sizes size:e(XS,S,M,L,XL,XXL,XXXL) # Colors (limited palette) color:e(red,blue,green,black,white,gray) # Categories category:e(electronics,clothing,home,sports,beauty) # Shipping options shipping:e(standard,express,overnight,pickup) # Ratings rating:e(1,2,3,4,5)
🌐 Web & API
# HTTP methods method:e(GET,POST,PUT,PATCH,DELETE) # Response status categories status_type:e(success,redirect,client_error,server_error) # Content types content:e(json,xml,html,text,binary) # Cache policies cache:e(none,private,public,immutable)
🔧 DevOps
# Environments env:e(dev,staging,prod,test,qa) # Deployment status deploy_status:e(pending,running,success,failed,rolled_back) # Server status server_status:e(online,offline,maintenance,degraded) # Alert severity alert:e(info,warning,critical,resolved)
📅 Time & Scheduling
# Days of week day:e(mon,tue,wed,thu,fri,sat,sun) # Recurrence recurrence:e(once,daily,weekly,monthly,yearly) # Time zones (abbreviated) tz:e(UTC,EST,PST,GMT,GST,IST,JST,CST)
Validation Behavior
✅ Valid Values
# Schema status:e(active,inactive,pending) # ✅ These are VALID: active # Exact match inactive # Exact match pending # Exact match
❌ Invalid Values
# Schema status:e(active,inactive,pending) # ❌ These are INVALID: Active # Wrong case! ACTIVE # Wrong case! active # Leading space! active # Trailing space! actve # Typo! enabled # Not in list!
Validation in Code
from dtl_parser import DTLParser parser = DTLParser() doc = parser.parse_file("data.dtl") # Validate - returns list of errors errors = doc.validate() for error in errors: print(f"Row {error.row}, {error.field}: {error.message}") # Output: Row 3, status: Value 'actve' not in allowed enum values: [active, inactive, pending]
Best Practices
✅ Do
- Use lowercase for consistency
- Use underscores for multi-word:
in_progress - Keep values short and clear
- Document enum meanings in comments
- Use enums for any fixed set of values
❌ Don't
- Use spaces in values (hard to debug)
- Mix cases:
Active,PENDING,done - Use more than 10 values (split if needed)
- Use enums for free-form text
- Forget enums are case-sensitive
Naming Conventions
# ✅ Good - lowercase, consistent status:e(pending,active,completed) priority:e(low,medium,high) # ✅ Good - uppercase codes currency:e(USD,EUR,GBP) method:e(GET,POST,PUT) # ✅ Good - underscores for compound status:e(in_progress,not_started,on_hold) # ❌ Bad - mixed case status:e(Pending,ACTIVE,Done) # ❌ Bad - spaces status:e(in progress,not started)
Advanced Patterns
Combining Multiple Enums
ORDERS|id:s,status:e(pending,shipped,delivered),priority:e(low,medium,high),payment:e(pending,paid,refunded)|3|S0|W0|C0 ORD001|pending|high|paid ORD002|shipped|medium|paid ORD003|delivered|low|refunded
Enum with Other Types
PRODUCTS|sku:s,name:s,price:f,category:e(electronics,clothing,home),stock:i,available:b|2|S0|W0|C0 SKU001|Laptop|999.99|electronics|50|1 SKU002|T-Shirt|29.99|clothing|200|1
State Machine Pattern
# Order states with allowed transitions # pending → confirmed → processing → shipped → delivered # ↓ ↓ ↓ # cancelled cancelled returned ORDERS|id:s,state:e(pending,confirmed,processing,shipped,delivered,cancelled,returned)|...|S0|W0|C0
SDK Integration Examples
All DTL SDKs provide full enum validation with autofix capabilities:
🐍 Python - Enum Validation & Autofix
from dtl_parser import DTLParser, create_table, find_closest_match # Create table with enum fields orders = create_table("ORDERS", { "id": "s", "status": "e(pending,processing,shipped,delivered,cancelled)", "priority": "e(low,medium,high,critical)", "payment": "e(pending,paid,failed,refunded)", }) # Add row - enum values are validated! orders.add_row({ "id": "ORD001", "status": "pending", # Valid "priority": "high", # Valid "payment": "paid", # Valid }) # Parse content with typos dtl_with_typos = """ ORDERS|id:s,status:e(pending,shipped,delivered)|2|S0|W0|C0 ORD001|pendng ORD002|shiped """ parser = DTLParser() doc = parser.parse(dtl_with_typos) # Validate - find enum errors errors = doc.validate() for err in errors: print(f"Error: {err.message}") print(f" 💡 Suggestion: {err.suggestion}") # Error: Invalid enum value "pendng". Allowed: pending, shipped, delivered # 💡 Suggestion: pending # Autofix - automatically correct typos! fixed_doc, changes = doc.autofix() for change in changes: print(f"✨ {change}") # ✨ Fixed ORDERS[0].status: 'pendng' → 'pending' # ✨ Fixed ORDERS[1].status: 'shiped' → 'shipped' # Fuzzy matching for custom suggestions allowed = ["pending", "processing", "shipped", "delivered"] suggestion = find_closest_match("procsesing", allowed) print(suggestion) # "processing"
📘 TypeScript - Enum Validation & Autofix
import { parse, validate, autofix, createTable, findClosestMatch, DtlType } from 'dtl-parser'; // Create table with enum fields const orders = createTable('ORDERS', { id: 's', status: 'e(pending,processing,shipped,delivered,cancelled)', priority: 'e(low,medium,high,critical)', }); // Add rows orders.rows.push({ id: 'ORD001', status: 'pending', priority: 'high', }); // Parse with errors and validate const doc = parse(dtlWithTypos); const errors = validate(doc); errors.forEach(err => { console.log(`Error: ${err.message}`); if (err.suggestion) { console.log(` 💡 Suggestion: ${err.suggestion}`); } }); // Autofix all errors const [fixedDoc, changes] = autofix(doc); changes.forEach(c => console.log(`✨ ${c}`)); // Custom fuzzy matching const suggestion = findClosestMatch('shiped', ['pending', 'shipped', 'delivered']); console.log(suggestion); // "shipped"
💜 C# - Enum Validation & Autofix
using Dtlaz.Parser; // Create table with enum fields var orders = DtlFactory.CreateTable("ORDERS", new Dictionary<string, string> { { "id", "s" }, { "status", "e(pending,processing,shipped,delivered,cancelled)" }, { "priority", "e(low,medium,high,critical)" }, }); // Add row orders.AddRow(new Dictionary<string, object?> { { "id", "ORD001" }, { "status", "pending" }, { "priority", "high" }, }); // Parse and validate var parser = new DtlParser(); var doc = parser.Parse(dtlWithTypos); var errors = doc.Validate(); foreach (var err in errors) { Console.WriteLine($"Error: {err.Message}"); if (err.Suggestion != null) Console.WriteLine($" 💡 Suggestion: {err.Suggestion}"); } // Autofix var (fixedDoc, changes) = doc.Autofix(); foreach (var change in changes) Console.WriteLine($"✨ {change}"); // Fuzzy matching var options = new List<string> { "pending", "shipped", "delivered" }; var suggestion = DtlHelpers.FindClosestMatch("shiped", options); Console.WriteLine(suggestion); // "shipped"