One LLM Call, Not Two: Getting Structured Output Directly from Your Pega AI Agent

One LLM Call, Not Two: Getting Structured Output Directly from Your Pega AI Agent


The Opportunity: Structured Agent Response Ready for User Action

When a Pega AI Agent completes analysis—whether assessing risk, recommending actions, enriching data, or flagging issues—it returns findings as intelligent prose. The agent works perfectly. But here is what becomes possible next: structured output that displays directly on the screen, ready for user action.

When agent findings remain as text paragraphs, workers must read and interpret them manually. They extract insights by hand. The findings never populate grids, appear in decision flows, or drive next actions. The intelligence stays trapped in unstructured text.

The opportunity is clear: structured output enables agent intelligence to flow directly into user screens and automated workflows.


The Single-Call Advantage Over Two-Call Approaches

Some implementations use a second LLM call to extract and structure agent findings. Take the agent’s prose, pass it through a second Gen AI Connect service, and ask a second LLM to parse it.

This approach works, but carries costs that compound at scale:

Double the inference cost Every agent invocation triggers two separate LLM API calls. For a high-volume application processing hundreds of cases per day, this doubles the inference spend for every agent interaction—without adding reasoning value. The second call does no thinking; it only reformats what the first call already produced.

Double the latency Two sequential LLM calls mean two round-trip wait times before your worker sees a result. In an assignment context where a worker is waiting to proceed, this degrades user experience significantly.

Two points of failure If either call fails, times out, or returns an unexpected format, the entire flow breaks. Error handling, retry logic, and fallback paths must now be designed and maintained for two calls independently. Each failure surface grows the operational risk.

Prompt fragility compounds The second prompt must accurately interpret what the first prompt produced. LLMs naturally vary their phrasing—“Case #12345 is a duplicate of Case #67890” versus “Cases 12345 and 67890 appear to be duplicates.” Small variations in the first agent’s output can confuse the extraction prompt, leading to silent data loss or misattributed values.

An architectural choice, not a necessity The fundamental point: modern LLMs are fully capable of producing structured output. The two-call pattern persists because agents are simply not instructed to respond in structured format. It is an optional approach, not a requirement. A single instruction changes everything.


The Root Cause: Missing Format Instruction

LLMs do not invent output formats by themselves. They follow instructions.

If you ask an LLM, “Analyze these cases for duplicates,” it will return a paragraph. If you ask it, “Analyze these cases and respond only with a valid JSON object conforming to this exact schema,” it will return JSON.

Modern LLMs—reliably produce valid, schema-conformant JSON when explicitly instructed to do so in the system prompt or agent instruction field.

The fix is prompt-level instruction:

Respond ONLY with a valid JSON object. Do not include any explanation, preamble, or markdown. Use exactly the schema provided below.

With this instruction, the agent performs its full reasoning in a single LLM call and returns structured data in one shot. No second call needed.


Implementation: Two Approaches

Both approaches start with the same agent instruction, then differ in how you parse the response. Choose based on your flow complexity and maintainability preference.

Agent Instruction (Both Approaches)

Add a strict JSON format instruction to your Pega AI Agent’s instruction field. No utilities or integrations required.

Generic Agent Instruction Template:

You are an analyst. Perform your analysis.

IMPORTANT: Respond ONLY with a valid JSON object.
Do not include any explanation, preamble, or markdown.

The JSON must conform exactly to this schema:

{
  "findings": [
    {
      "id": "string",
      "category": "string",
      "confidence": number (0-100),
      "summary": "string",
      "recommendation": "string"
    }
  ],
  "overallAssessment": "string",
  "priority": "High | Medium | Low",
  "suggestedActions": ["string"]
}

Customize the schema for your agent’s purpose. Risk assessment agents use risk fields. Enrichment agents use data fields. Routing agents use assignment fields. The structure adapts to your need—the instruction pattern stays the same.

That is all. The agent performs the same analysis, but now it responds with structured data instead of prose. The structured JSON displays directly on the worker’s screen, ready for action.


Option 1: Direct JSON Parsing (Simplest)

One action in your data transform. Agent returns JSON. Parse directly to clipboard page. Display on screen.

Data Transform Configuration:


Option 2: Parameterized Multi-Step Approach (More Control)

Separate agent output capture, deserialization, and page update into distinct steps. Useful for complex flows, validation, or auditing.

Data Transform Configuration:

Both Option 1 & 2, once parsed onto a clipboard page, the agent’s structured output becomes Pega data:

  • Display directly in assignment worklists and case summaries
  • Bindable to repeating grids for user review
  • Usable in decision rules for automated routing
  • Mappable to case properties for persistence
  • Available to trigger next-step automation

Why This Approach Wins

Aspect One Call Two-Call Pattern
LLM Calls 1 2
Cost Full inference cost Double cost
Latency Single round trip Two round trips
Error Points 1 failure surface 2 independent failure surfaces
Prompt Risk Schema enforced at source Second prompt interprets first output
Workflow Integration Direct—data is already structured Requires extraction and mapping

Single LLM call. Reasoning and structuring happen in one inference. No extraction layer.

Half the cost. You eliminate the second Gen AI Connect service call entirely. For high-volume applications, this is a direct cost reduction.

50% less latency. One round trip instead of two. Your worker sees actionable results faster.

Simpler error handling. One call means one set of retry logic, one error state, one monitoring path. Operational complexity drops.

No prompt fragility. There is no second prompt trying to interpret the first prompt’s natural language variations. The JSON schema is enforced at the source.

Workflow-native output. The response lands as structured Pega data—ready for grids, decisioning, property mapping, and case automation. No manual interpretation required.


Sample Output:


Design Patterns: Where This Works Best

This pattern applies to any Pega AI Agent response that needs to display on screen or drive action. Most valuable in these scenarios:

Risk Assessment & Fraud Detection Agent analyzes a case for risk, returns findings as structured JSON. Workers see risk score, flags, and recommended actions directly in the assignment. No second extraction call. Cost: 50% lower. Speed: 50% faster.

Case Enrichment & Data Completion Agent enriches case with suggested category, product, knowledge articles. Structured JSON populates suggestion widgets. Workers accept or modify. Direct display, no extraction layer.

Intelligent Routing & Triage Agent recommends assignment, queue, or priority. Structured JSON drives routing decision in real time. Workers see recommendation on screen. Automation acts immediately.

Compliance & Policy Checking Agent checks case against policy rules. Returns violations, severity, and required actions as JSON. Compliance team sees findings structured and actionable. No manual interpretation.

High-Volume Case Processing Every agent invocation across hundreds or thousands of daily cases: one LLM call instead of two. Cost scales directly with volume. A 50% reduction compounds fast across large case loads.

Real-Time User Interaction When workers are waiting for agent findings to make a decision, 50% latency reduction matters. Structured output displays immediately for action.


Related Pega Resources

For additional Pega Agentic AI recipes, patterns, and production-ready guidance, see the Pega GenAI Cookbook: Agentic AI Recipes—a continuously updated collection covering MCP, Agent-to-Agent orchestration, Knowledge Buddy, Copilot, LangGraph, and related enterprise AI patterns.