Home / Prompts / Coding / DeepSeek for API Developers: Write a Regex Validation Library
💻 Coding Prompt

DeepSeek for API Developers: Write a Regex Validation Library

Advanced DeepSeek prompts for API Developers writing regex pattern libraries for input validation
🔥 1.6K uses
🤖 DeepSeek
✅ Free to use
The Prompt
You are an expert API developer with 11 years of experience writing input validation systems for SaaS platforms where poorly validated API inputs are the primary source of both data corruption bugs and injection attack surfaces, and where a well-documented regex pattern library reduces the time to add new endpoint validation from 40 minutes of ad hoc pattern writing to under 5 minutes of selecting a tested, documented pattern from a shared library. Help me write a regex pattern library so I can reduce production bugs and ship an API input validation library that covers all current endpoint input types, is fully tested, and is documented clearly enough that any developer on the team can use it without needing to understand regex syntax. My situation: - API type and language: [e.g., "a multi-tenant SaaS API built in TypeScript with Fastify — the API serves a B2B project management platform with 140 endpoints — input validation currently uses a mix of Zod schemas, ad hoc regex written inline, and some endpoints with no validation at all"] - Current validation problem: [e.g., "the last three production bugs were caused by: an endpoint that accepted an empty string as a project name and stored it in the database (no minimum length validation), a date field that accepted '13/45/2024' without error (regex not anchored to full string), and a user ID field that accepted SQL fragment syntax because no alphanumeric restriction was applied"] - Input types requiring regex patterns: [e.g., "eight categories of input requiring standardized patterns: email addresses, phone numbers (international E.164 format), ISO 8601 date strings, UUIDs v4, project names (alphanumeric with hyphens and spaces, 2-80 chars), API key format (prefix_base64, e.g., sk_live_xxxx), URL with HTTPS requirement, and slug format (lowercase alphanumeric with hyphens, no leading or trailing hyphens)"] - Team regex experience: [e.g., "three of the five developers on the team describe their regex skills as 'I can read simple patterns but I cannot write them reliably' — the library must be usable by these developers without requiring them to modify the patterns"] - Testing framework: [e.g., "Vitest for unit testing — the pattern library must have a test suite that covers the valid input cases, the edge cases, and the known attack payloads that must be rejected for each pattern"] - Integration requirement: [e.g., "the pattern library must be compatible with Zod's .regex() method so existing Zod schemas can adopt the patterns without restructuring — the library should export each pattern as a named RegExp constant and as a Zod schema extension"] - Documentation requirement: [e.g., "each pattern must be documented in a format a junior developer can understand: what it matches, what it rejects, three valid examples, three invalid examples, and any known limitation or edge case the developer must be aware of"] Deliver: 1. A TypeScript regex pattern library file — a patterns.ts file exporting eight named RegExp constants (EMAIL_PATTERN, E164_PHONE_PATTERN, ISO8601_DATE_PATTERN, UUID_V4_PATTERN, PROJECT_NAME_PATTERN, API_KEY_PATTERN, HTTPS_URL_PATTERN, SLUG_PATTERN) with each pattern anchored to full string match (^ and $) and a JSDoc comment block for each constant covering the description, valid examples array, invalid examples array, and known limitations 2. A Zod integration module — a zod-patterns.ts file that extends each RegExp constant into a Zod schema with a descriptive error message (not the default 'Invalid input' Zod error) and exports each as a named Zod schema (emailSchema, e164PhoneSchema, etc.) — with a usage example showing how to replace an existing inline Fastify Zod schema validation with the library schema 3. A Vitest test suite for the pattern library — a patterns.test.ts file with at minimum 6 test cases per pattern (2 valid inputs, 2 invalid inputs, 1 boundary case, 1 known attack payload or injection attempt) covering all 8 patterns — each test case with a comment explaining why the input is valid or invalid in plain English for the three developers with low regex confidence 4. A pattern failure analysis for the three production bugs — a documented explanation of why each of the three bugs occurred (empty string acceptance, unanchored date regex, unvalidated user ID field) and the specific pattern or pattern combination from the new library that prevents each bug — formatted as a code comment block in the pattern file that the tech lead can reference in the post-mortem 5. A developer usage guide — a markdown document covering how to import and use the pattern library in a new Fastify endpoint (four code examples: inline regex validation, Zod schema validation, the error message the API returns on validation failure, and how to add a new pattern to the library following the existing format) 6. A pattern audit script — a TypeScript script that scans all Fastify route files for string fields that do not use a pattern from the library (identified by inline regex literals or missing .regex() calls on string Zod fields) and outputs a report of unprotected endpoints grouped by the likely input type — enabling the tech lead to prioritize which existing endpoints need migration to the new library 7. A pattern library maintenance protocol — a set of rules for adding new patterns to the library, covering the required test case count (minimum 6 per pattern), the review process (at least one developer who did not write the pattern must verify all test cases pass and the JSDoc examples are accurate), and the versioning strategy for breaking changes to an existing pattern (a deprecation period of two releases before removing the old pattern constant) **Write every regex pattern with explicit anchoring, write every JSDoc comment with the same clarity standard as public API documentation, and write every test case comment in plain English that a developer who has never seen a regex can read and understand — the library's value is not in the patterns alone but in the documentation and test coverage that makes the patterns usable by every developer on the team regardless of their regex experience.**

💡 How to use this prompt

  • Write and test the ISO8601_DATE_PATTERN from output item 1 first, with its full Vitest suite from output item 3. The unanchored date regex that accepted '13/45/2024' is the most instructive pattern to get right first — anchoring errors are the single most common regex mistake in production codebases, and building the date pattern with full anchor enforcement and the boundary test case (a date string with trailing whitespace) sets the quality standard for every subsequent pattern in the library.
  • The most common mistake is writing the JSDoc examples with only clean, clearly valid inputs as the valid examples and obviously malformed strings as the invalid examples. A developer who needs the documentation is the same developer who will try a borderline input like a phone number with spaces between digits or a project name with a leading hyphen. The three invalid examples in each JSDoc block must include at least one borderline case that looks plausible, not just an obviously wrong input.
  • DeepSeek handles this at a fraction of the API cost of GPT-4o or Claude. Use DeepSeek R1 with Deep Thinking mode enabled for the regex pattern construction — complex anchoring, lookahead, and character class edge cases benefit from extended reasoning. For the developer usage guide and the maintenance protocol, review DeepSeek's data storage policy if the API codebase context you paste contains proprietary route structures.
Best Tools for This Prompt
🤖 Best AI Coding Tools for This Prompt
Tested & reviewed — run this prompt with the best AI tools
View All Tools →
Cursor AI
★ 4.7 Free / From $20/mo
Cline
★ 4.6 Free & Open Source · Teams Custom
GitHub Copilot
★ 4.6 Free / From $10/mo
Related Topics
#API Input Validation #DeepSeek #Regex Pattern

About This Coding AI Prompt

This free Coding prompt is designed for DeepSeek and works with any modern AI assistant including ChatGPT, Claude, Gemini, and more. Simply copy the prompt above, paste it into your preferred AI tool, and customize the bracketed sections to fit your specific needs.

Coding prompts like this one help you get better, more consistent results from AI tools. Instead of starting from scratch every time, you can use this tested prompt as a foundation and adapt it to your workflow. Browse more Coding prompts →

Affiliate Disclosure: This page contains affiliate links. If you click and make a purchase, we may earn a small commission at no extra cost to you. We only recommend tools we genuinely believe in.

🎯 Explore More

Discover other curated resources from our platform

🛠️ AI Tools View All →
Appmixo
Appmixo
★ 4.0
Aha
Aha
★ 3.8
MuleRun
MuleRun
★ 3.6
⚔️ VS Comparisons View All →
ChatGPT vs Gemini: Which AI Writing Tool Wins in 2026?
ChatGPT vs Gemini: Which AI Writing…
⚔️
ChatGPT vs DeepSeek: Which AI Is…
ChatGPT GPT-4o vs DeepSeek R1
ChatGPT vs Grok: 2026 Comparison — Pricing, Features & Verdict
ChatGPT vs Grok: 2026 Comparison —…
ChatGPT vs Grok
💡 Free Prompts View All →
💡
Expert Guide: Fix Poor Recipe SEO…
🔥 3.4K uses
💡
Stop Publishing Finance Research Proposals That…
🔥 3.8K uses
💡
Intermediate-Level Claude Prompts for Executive Assistants…
🔥 0.8K uses