Input Validation vs Smart Abstraction

Both are commonly confused. Here is a side-by-side breakdown of what each one does, when to reach for it, and when it would be the wrong choice.

Input Validation

Validation = checking data is correct (email has @). Sanitization = removing danger (no tags). Use BOTH. Validation catches mistakes, sanitization stops attacks.

Read full block →

Smart Abstraction

Smart Abstraction = One function that tries multiple ways to get the job done. Primary fails? Try the backup. Backup fails? Use the cache. Your app keeps working.

Read full block →

When to use each

Use Input Validation when

  • You accept ANY data from users

    Forms, search boxes, API endpoints, file uploads. If a user can type or send something, you need to validate it. Never trust input you didn't create.

  • Data will be stored or displayed

    Before saving to a database or showing on a page, validate. Bad data in your database causes bugs forever. Bad data on your page can even attack other users (XSS).

  • You're building any login or signup flow

    Email must be real. Password must meet requirements. Username can't have special characters. These validations protect your users and your system.

  • You process payments or sensitive data

    Credit card numbers have specific formats. Social security numbers have rules. Validating these fields catches typos before expensive payment failures.

Use Smart Abstraction when

  • You call external APIs that might fail

    AI providers have outages. Scraping sites go down. Payment APIs hit rate limits. A smart function retries and falls back automatically, so your users never see "Service Unavailable."

  • You want to switch providers without rewriting code

    Today you use OpenAI, tomorrow you want Claude. With smart abstraction, you update ONE function. Without it, you hunt through 50 files changing API calls.

  • You need to reduce costs with cheaper fallbacks

    Use the expensive fast API for speed, but fall back to a cheaper option when budgets are tight. Or use free scraping first, then paid APIs when free fails.

  • Your app can't afford downtime

    Production apps need reliability. A smart function with fallbacks means one provider's bad day doesn't become your bad day.

When to avoid each

Avoid Input Validation when

  • Data comes from your own code

    If you're passing data between functions you wrote, you don't need to validate again. Validation is for untrusted input: external data you can't control.

  • You're over-validating

    Don't reject valid data with overly strict rules. Not all phone numbers are 10 digits. Not all names use only letters. Validate for safety, not arbitrary formatting.

Avoid Smart Abstraction when

  • You're building a quick prototype

    If you're just testing an idea, don't worry about fallbacks yet. Get it working first, then add resilience when you know it's worth building.

  • Only one provider exists for your use case

    Some APIs are unique. If there's truly no alternative, smart abstraction can still help with retries, but fallbacks need somewhere to fall back to.

  • The operation is local and reliable

    Reading a local file doesn't need fallback logic. Smart abstraction is for unreliable external dependencies, not internal operations.