Skip to content
Putting technology to work.
Insights to guide decisions and action.

Search articles

Google Genkit Middleware launched — Designing cross-cutting AI app layers in custom development 2026

Table of contents · 11 items

On May 24, 2026, InfoQ published Google Introduces Middleware Architecture for Genkit Applications. A middleware architecture serving as a cross-cutting interception layer for model invocations, tool executions, and overall flows has been implemented in Genkit, Google's open-source framework for AI and agent applications. As a result, observability, cost controls, security, and guardrails structurally shift from fragmented, in-house implementations across application code to centralized processing within an intermediate layer.

From the perspective of supporting AI application foundations for mid-sized enterprises via custom development, this adds a standard architectural option to solve the classic challenge where "PoCs have proliferated, but a governance layer for production operations is missing." Genkit Middleware makes it possible to implement the "governance outside the application" covered in our Anthropic monthly credit budget governance client engagements and Validating Agentic Behavior trust layer client engagements as a "cross-cutting layer integrated directly with the application." This article outlines the key concepts and procedures for designing cross-cutting layers for AI applications based on Genkit Middleware.

Why middleware is becoming the primary battleground for AI apps

DimensionConventional AI app implementationGenkit Middleware-based
Observability & tracingHandwritten across application codeCentrally collected via middleware
Cost aggregationPer-application / retroactive aggregationReal-time / standardized aggregation
GuardrailsEmbedded in promptsApplied uniformly in the intermediate layer
CacheImplemented per featureApplied transparently via middleware
Retries & fallbacksScattered try-catch blocksUnified policy
Permissions & authenticationImplemented in each API callHandled collectively at request boundaries
A/B testingFeature-specific flagsMiddleware routing

In other words, Genkit Middleware provides the same abstraction as Express / Connect middleware in web applications for AI-specific model calls, tools, and flows, serving as the "standard governance layer for AI applications."

Three structural changes beneficial to custom development projects

Structure 1: From "cross-cutting logic scattered across the application layer" to "intermediate layer centralization"

Historically, AI applications frequently suffered from logging, cost aggregation, prompt sanitization, and response validation being implemented separately inside individual features. Because Genkit Middleware can inject common hooks before and after model, tool, and flow invocations, you can centralize cross-cutting processing in a single place. This is a step toward embodying in the implementation layer the common specifications addressed in our AGENTS.md / SKILL.md / DESIGN.md custom architectural design engagements.

Structure 2: From "single-model assumptions" to "multi-model switching"

Because Genkit Middleware can route requests immediately prior to model invocation, switching between OpenAI, Anthropic, Google, xAI, and on-premises LLMs can be achieved without modifying application code. Combining this with our multi-LLM agent infrastructure client engagements (including Grok) provides a two-tier defense across the gateway layer + middleware layer, bolstering operational robustness.

Structure 3: From "retroactive production metrics" to "standardized production telemetry"

Genkit Middleware allows telemetry hooks for OpenTelemetry, Langfuse, Datadog, and others to be integrated by default. Instead of tacking on APMs after going live, teams can transition to an architecture designed for telemetry from day one. This is the standard form of "observability-driven AI applications," extending the principles of our Validating Agentic Behavior trust layer client engagements.

Five phases of adopting a cross-cutting layer with Genkit Middleware

Phase 1: Current state assessment (2 weeks)

  • Inventory existing AI applications (frameworks / models / feature counts)
  • Review implementation status of observability, cost tracking, and guardrails
  • Assess visibility level into monthly LLM costs
  • Categorize existing PoCs versus production applications
  • Prioritize candidates for middleware adoption

Phase 2: Middleware design (1–2 weeks)

  • Determine Genkit adoption scope (greenfield vs. legacy replacement)
  • Design middleware stack (observability / cost / guardrails / caching)
  • Establish multi-LLM routing policies
  • Design guardrails (PII masking / prompt injection defenses)
  • Select telemetry backends (Langfuse / OpenTelemetry / Datadog)

Phase 3: PoC implementation (2–3 weeks)

  • Apply middleware to 1–2 representative applications
  • Compare against existing implementations (accuracy / cost / labor)
  • Measure performance overhead
  • Evaluate guardrail detection rates
  • Evaluation report creation

Phase 4: Production rollout (3–4 weeks)

  • Execute phased migration of existing AI applications
  • Establish canary deployments and rollback procedures
  • Monitoring dashboard construction
  • Incident response runbook development
  • Knowledge transfer to operations team

Phase 5: Monthly operational reviews (ongoing)

  • Track LLM costs / request counts passing through middleware
  • Monitor guardrail detection counts / false positive rates
  • Review utilization status of observability traces
  • Handle requests for adding new middleware
  • Track Genkit version updates

Standard technology stack set for custom development

LayerRecommended technologyAlternative
FrameworkGenkit(Node.js / Go)LangChain / Haystack
ObservabilityLangfuse + OpenTelemetryPhoenix / Helicone
Cost aggregationLangfuse + GrafanaCustom BI
GuardrailsNeMo Guardrails / Lakera GuardIn-house custom middleware
CacheRedis Semantic CacheGPTCache
Model deliveryOpenAI / Anthropic / Google / xAI / BedrockVertex AI
SecretsHashiCorp VaultSecrets Manager
CI/CDGitHub Actions + Genkit CLIGitLab CI

Which projects need this and which do not

Projects requiring thisProjects not requiring this
Multiple AI apps (5+) running concurrentlyOne-off PoCs only
Monthly LLM spend of ¥1M or moreTens of thousands of yen monthly
Guardrails / compliance requirementsUnrestricted internal tools
Need for multi-model switchingFixed to a single model
Desire to build out full-fledged observability / tracingTrial operation phase

Six clauses to include in client contracts

ClauseDetailsWhat the client should verify
Target application scopeGreenfield / legacy / phased migrationBusiness impact level
Observability platformLangfuse / OTel / DatadogInformation security policy
Cross-border data transferDestination for prompts / responsesRegulatory requirements
Guardrail ownershipScope of detection / blockingOperational requirement
Cost aggregationAccuracy by model / departmentInternal controls
Handover Upon Project CompletionMiddleware + configuration + dashboardsInternal operational continuity

ROI estimate (assuming 6 AI apps / 1.5 million JPY monthly LLM spend)

ItemIn-house cross-cutting logic in application layerCentralized with Genkit MiddlewareDifference
Engineering effort for cross-cutting logic (annual)900h250h-650h
Monthly LLM cost (after cost optimization)1.5 million yen¥950,000-550,000 JPY
Guardrail false-negative incidents60 incidents / year8 incidents / year-52 incidents
Observability black hole timeAverage 30%Average 5%-25pt
Estimated incident losses10 million JPY / year2 million JPY / year-8 million JPY
Annual benefitEquivalent to approx. 18 million JPY + enhanced observability infrastructure

Even calculated at an hourly rate of 8,000 JPY, the net annual reduction is estimated to exceed 15 million JPY. However, because the investment required for middleware adoption varies substantially based on the number of target applications, observability requirements, and the migration complexity of existing code, please calculate your payback period based on your organization's specific assumptions.

Five common pitfalls

Pitfall 1: Migrating existing applications to middleware all at once

Migrating every application at once, including PoCs, leads to introduced bugs and massive verification overhead. A phased rollout starting with production systems is the safer path.

Pitfall 2: Overly strict guardrails

Configuring PII masking or prompt sanitization with overly aggressive thresholds causes business disruptions by blocking legitimate requests. It is vital to operate by raising thresholds incrementally.

Pitfall 3: Overlooking telemetry and observability costs

The volume of ingested events in Langfuse or Datadog surges rapidly with AI applications. Design sampling, compression, and retention period optimization from the very beginning.

Pitfall 4: Response discrepancies when switching models

When switching models via middleware, variations in response format, token consumption, and accuracy ripple into the application layer. Include an A/B evaluation workflow in your contract.

Pitfall 5: Lacking a version tracking plan

Genkit is evolving rapidly (incurring version tracking overhead). Explicitly specify monthly evaluations + semiannual major version upgrades in your contract to keep unexpected costs under control.

90-day action plan

WeekAction
Week 1〜2AI application inventory + middleware candidate selection
Week 3〜4Middleware stack design + observability platform selection
Week 5〜7PoC implementation + telemetry / guardrail evaluation
Week 8〜9Production canary + phased rollout
Week 10Monitoring dashboard + runbook development
Week 11〜13Full application migration completion + launch of monthly operations

Summary — The arrival of an era where "AI apps also enter the middleware era"

With the arrival of Google Genkit's middleware architecture, the pattern of batch-processing cross-cutting AI app governance in an intermediate layer has become the new standard for mid-sized enterprise AI application foundations. What is critical is designing middleware architecture, observability, guardrails, and operational reviews not in silos, but as a cohesive, integrated architecture. If any single piece is developed in isolation, cross-cutting logic will ultimately creep back into the application layer.

If you are facing challenges such as "observability for AI applications always lagging behind," "inability to see or control LLM costs," or "wanting to apply guardrails across the board," we provide custom estimates after reviewing your target application configurations and requirements. Please feel free to get in touch via our contact form.

Sources

Share this articleXFacebook
Kakeru Suzuki

Fascinated by the possibilities of technology, has had a deep interest in programming and digital art since student days

Turn this article's theme into your company's next step

Thinking together, starting from the work you entrust to AI.

We organize your current operations and data to define the scope entrusted to AI, what humans should review, and how to run trials.

  • Target operations
  • Data to use
  • How to verify effectiveness
Consult on AI adoption for your business

You can consult with us from the initial conceptual stage. Details from this article will be carried over to the inquiry form.

Receive the latest articles by email