Pipeline stages
The message enhancer runs a two-stage pipeline on every complete agent response:1
Language detection
Gemini identifies the conversation language from the raw response text, returning an ISO 2-letter code (e.g.,
es, en, pt). The detected language is used to enforce linguistic consistency in the formatted output.If language detection fails, the enhancer defaults to Spanish (es).2
Structured formatting
The raw text is converted into a structured JSON object matching one of four component types. Gemini evaluates the content and selects the appropriate format:
The enhancer enforces the detected language across all output fields —
content, options, list_title, button, and link text.Output constraints
The enhancer enforces WhatsApp Business API field limits:
If any field exceeds its limit, Gemini summarizes the content to fit within the constraint. Options and button labels do not include emojis.
WhatsApp-specific formatting
The enhancer applies contextual emoji hints for financial operations:
Bold text is converted from markdown double-asterisk (
**) to WhatsApp single-asterisk (*) format. Newlines are stripped from the structured output.
Model configuration
The message enhancer runs on Gemini 2.5 Flash Lite via Google Cloud Vertex AI. Vertex AI supports VPC Service Controls, which allows all inference traffic to remain within the bank’s GCP perimeter — conversation data sent for enhancement never leaves the controlled network boundary.
The
only_full_messages=True setting ensures enhancement runs only on complete responses, not on streaming fragments. This guarantees the enhancer has the full message context before selecting a component type.
Gemini on Vertex AI operates under Google Cloud’s enterprise data processing terms: zero data retention, no model training on customer data, and full compliance with VPC Service Controls for network isolation.
Fallback behavior
If the enhancer fails for any reason — model error, invalid JSON output, parsing failure — the response falls back to a plainOutgoingTextMessage with the original text. No message is lost.
Security considerations
- No data generation: The enhancer reformats existing text — it does not generate new content, invoke tool functions, or access backend services.
- Language enforcement: The two-stage pipeline detects and enforces the conversation language, preventing mixed-language responses that could confuse senders.
- Deterministic output: Temperature and top-p settings are configured for consistent, structured output rather than creative variation.