How Nakodo’s Codebase Splits Zod Schemas Between User Input and AI Parsing

Nakodo · Codebase architecture: Nakodo codebase splits Zod schemas for input and AI

An examination of the Nakodo codebase—an AI-driven business and creator outreach application—reveals a distinct architectural pattern in how data validation is handled using Zod version 4.6.5 across 27 files and 70 z.object schemas. Rather than treating validation as a monolithic task, the application divides its schemas into two distinct populations that serve entirely opposite functions, discernible immediately by their invocation shapes.

Managing User Input With Safe Parsing

The first major schema group handles incoming user submissions through server actions where payloads arrive as unknown types because endpoints accept external POST requests. Across nine files, 39 safeParse invocations process inputs for features such as campaign actions, account settings, support tickets, and authentication workflows. Validation failures here are treated as routine operational occurrences rather than exceptional errors, allowing forms to return descriptive feedback directly to users. Instead of generating complex error trees or comprehensive field maps, error handling inspects only the initial issue's message or path, displaying a single concise sentence at the top of the interface.

This user-facing validation layer also embeds product copy directly into schema definitions alongside custom refinement rules. For instance, base credentials schemas are extended using method chaining to enforce restrictions like blocking disposable email addresses specifically during account creation, leaving existing authentication flows uninterrupted.

Structured AI Outputs and Provider Constraints

In contrast, the second population of schemas governs structured data returned by language models handling text analysis, brief generation, and classification tasks. Spanning 15 files with 31 schemas, these definitions operate without local parse calls. Instead, schemas are transmitted to external AI providers as required output formats, relying on SDK validation and centralized parsing utilities.

Unlike user form validation where input malformations are expected, a model failing to return the declared schema structure represents a retryable system fault that raises exceptions rather than returning validation error objects. This domain also exposes distinct provider limitations, such as reliance on nullable properties instead of optional properties due to structural output constraints enforced by the underlying AI integration.

Why Error Responsibility Dictates Validation Architecture

The structural dichotomy observed in Nakodo highlights a foundational principle in modern application design: validation strategy should be dictated primarily by fault attribution rather than data type alone. When data originates from an external user interacting with a client form, validation failure is a normal human mistake or an automated bot interaction. The appropriate response is a gentle, actionable error message returned cleanly to the interface without disrupting server execution. Conversely, when data flows from a language model, an invalid shape is a system integration fault requiring retries and exception management. By separating these concerns, the codebase maintains high readability and prevents error-handling logic from becoming conflated across different system boundaries. Furthermore, specialized utility patterns—such as centralizing UUID checks into a reusable type predicate, restricting record sizes to prevent payload abuse, and isolating data transformations—demonstrate how disciplined library usage can simplify complex backend workflows. Developers building large-scale applications with AI components can apply similar boundary distinctions to determine whether a given schema should result in a graceful result object or a robust programmatic exception.

Editorial graphic and headline text by Signal Titans.

Source: Zod does two opposite jobs in our app, and the call shape tells you which one · How it works: the brief, the search and the score · Nakodo

Share this article
FacebookThreadsLinkedInX

Leave a Reply

Your email address will not be published. Required fields are marked *