On this page10
  1. At a glance
  2. The risk of trusting model output
  3. How the boundary works
  4. When the model fails, the response keeps its shape
  5. Where the model sits
  6. A payload that grew in versions
  7. A timeout that chose the model
  8. Key decision: one boundary, not many
  9. Result
  10. Hiring for AI that runs in production?

Part of my work on Google Search Intelligence. By Mohammad Javad Dastouri, full-stack and AI engineer.

Putting a language model in a production API path creates one central risk: its output is not guaranteed to match anything.

Stages for one URL
8
Lines in those stages
749
Nginx limit per request
60 s

At a glance

Area
AI and computer vision
My role
Sole engineer: design, build, deploy and run
Built with
Node.js 22, Express, Grok API
Used on
Google Search Intelligence
Model
grok-3-mini
Area
AI and computer vision
My role
Sole engineer: design, build, deploy and run
Built with
Node.js 22, Express, Grok API
Used on
Google Search Intelligence
Model
grok-3-mini

The risk of trusting model output

A consumer that trusts model-shaped JSON breaks on malformed output, partial responses, invented fields or provider downtime.

I treat the model as an untrusted upstream service. Everything it returns passes through one normalisation step before any consumer sees it.

How the boundary works

  • Defaults first

    output is merged onto safe defaults that specify every field, so every field exists before the model answers.

  • Types

    booleans must be booleans, and numbers must be numbers.

  • Allowed values

    position bands, for example, come from a fixed set, and anything else becomes null.

  • Defaults first

    output is merged onto safe defaults that specify every field, so every field exists before the model answers.

  • Types

    booleans must be booleans, and numbers must be numbers.

  • Allowed values

    position bands, for example, come from a fixed set, and anything else becomes null.

When the model fails, the response keeps its shape

The response has the same shape whether the model succeeds, returns malformed JSON or is unavailable. A total failure returns a fallback flag with null scores, not an exception.

Consumers need no defensive parsing, and an AI outage degrades one feature instead of breaking the endpoint.

Where the model sits

Analysis of a single URL runs through eight stages in 749 lines. The AI analysis is the seventh, just before the combined response is returned.

The eight stages of one URL analysis
  1. Resolve the live properties.
  2. Find the property that owns the URL.
  3. Call URL Inspection.
  4. Read 90 days of performance.
  5. Read the top queries.
  6. Build the extended breakdowns.
  7. Run the AI analysis.
  8. Return the combined response.

A payload that grew in versions

  • Version 2

    breakdowns by country, device, search type, appearance and date, plus country-query and country-device intersections.

  • Version 3

    a four-window view of 90, 60, 30 and 10 days, with daily series for the top seven countries in each window.

  • Payload size

    days with no impressions are left out.

  • Compatibility

    each revision was documented, and existing consumers kept working.

  • Version 2

    breakdowns by country, device, search type, appearance and date, plus country-query and country-device intersections.

  • Version 3

    a four-window view of 90, 60, 30 and 10 days, with daily series for the top seven countries in each window.

  • Payload size

    days with no impressions are left out.

  • Compatibility

    each revision was documented, and existing consumers kept working.

A timeout that chose the model

ModelTime it took

grok-3
About 35 seconds
grok-3-mini
About 8 to 12 seconds

ModelTime it took

grok-3
About 35 seconds
grok-3-mini
About 8 to 12 seconds

With the other stages to fit in as well, I chose the smaller model. The binding constraint in production work is often infrastructure and not the algorithm.

Key decision: one boundary, not many

Exhaustive validation of a large nested schema is tedious and shows no visible feature. Doing it at each caller would spread the same work and guarantee inconsistency.

Result

Validating, type-checking, allowlisting and defaulting at the boundary works for any integration where a provider cannot guarantee the shape of its response.

The same discipline applies to AI agents: connecting agents through MCP and auditing their work.

As AI moves into production request paths, the engineering problem shifts from calling the model to containing it.

Hiring for AI that runs in production?

Tell me about the role, or go back to the project: the system this method runs in.

Section
AI and computer vision
Updated
November 9, 2026
Reading time
3 min read

Hiring for this kind of work?

Tell me about the role and I will reply by email.

Discuss a role with me