AI Engineer Portal
Your personal operating system for career transition.
Exercise
Build an error classification and retry policy engine
Build an Error Classification and Retry Policy Engine
AI service calls fail in distinct categories, and each category calls for a different response. A 429 rate limit error should wait and retry. A 401 authentication error should fail immediately — retrying is pointless. A 500 server error should retry with backoff. A validation error in the response should log and skip, not retry.
Treating all errors the same (either always retry or never retry) wastes time on unrecoverable errors and abandons recoverable ones.
What to build
Implement an error classification and retry policy system:
ErrorCategoryenum with values:RATE_LIMITED,SERVER_ERROR,AUTH_ERROR,VALIDATION_ERROR,TIMEOUT,UNKNOWN.classify_error(error: Exception | dict) -> ErrorCategory— classifies an exception or error dict. Rules:- HTTP 429 or message containing "rate limit" →
RATE_LIMITED - HTTP 4xx (except 429) or "unauthorized"/"forbidden" →
AUTH_ERROR - HTTP 5xx or "internal server error" →
SERVER_ERROR TimeoutErroror "timed out" in message →TIMEOUTValueErroror "validation" in message →VALIDATION_ERROR- anything else →
UNKNOWN
- HTTP 429 or message containing "rate limit" →
RetryPolicydataclass with:should_retry: bool,max_attempts: int,base_delay_s: float,max_delay_s: float.get_retry_policy(category: ErrorCategory) -> RetryPolicy— returns the appropriate policy per category.AUTH_ERRORandVALIDATION_ERROR→ never retry.RATE_LIMITED→ retry up to 5 times, 60s base delay.SERVER_ERRORandTIMEOUT→ retry up to 3 times, 1s base delay.UNKNOWN→ retry once, 2s base delay.execute_with_retry(fn: Callable, *args, **kwargs) -> dict— wraps a callable, catches errors, classifies them, and applies the retry policy with exponential backoff. Returns{"result": ..., "attempts": int, "category": ErrorCategory | None}.
Why this matters
Production AI systems without explicit retry policies either retry too aggressively (hammering a rate-limited API) or not at all (failing on transient 500s). This classification layer makes retry behavior explicit, testable, and easy to tune per error type.
Constraints
execute_with_retrymust use exponential backoff:delay = min(base_delay * 2^attempt, max_delay).- Do not retry on
AUTH_ERRORorVALIDATION_ERRORunder any circumstances. - Use
time.sleep(synchronous version).
Data Transformation / hard / Step 12 of 16
Transform and summarize data safely
Think like an evaluation or trace pipeline: group clearly, preserve the data story, and make edge cases visible instead of clever.
- - Handles missing or noisy records predictably
- - Produces summary output that is easy to inspect
- - Would be safe to rerun in a script workflow
- - Do grouped metrics stay readable?
- - Would malformed rows be debuggable?
- - Did I choose names that explain the transformation?
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.