DEV Community

mikerawsonnz
mikerawsonnz

Posted on • Originally published at agents.getvda.ai

Structured Output: Gemini 2.5 Flash & Instructor for Validated JSON

Generating Structured Data with Ease: Introducing the Structured Output MCP Agent

Working with large language models often involves wrestling their free-form text output into a structured format for downstream processing. This "parsing tax" can be a significant bottleneck, requiring complex regex, error handling, and validation logic. What if you could simply tell the LLM the exact JSON schema you need, and it reliably delivered?

Enter the Structured Output MCP Agent. This powerful agent leverages the capabilities of instructor over Google's Gemini 2.5 Flash on Vertex AI, combined with fastmcp, to transform a natural language prompt and a JSON schema into validated, typed JSON output. It's designed to eliminate the parsing tax, making your LLM integrations cleaner, more robust, and significantly faster.

The Problem It Solves

Imagine you're building an application that extracts information from user queries – say, a booking system that needs to identify the destination, dates, and number of guests. Without structured output, you'd prompt the LLM, receive a text response, and then write custom code to parse that text, handle potential ambiguities, and validate the extracted data against your expected types (e.g., ensuring dates are actual dates, and guest counts are integers). This is brittle and time-consuming.

The Structured Output MCP Agent solves this by:

  • Guaranteed Schema Adherence: It forces the LLM to conform its output to your specified JSON schema, dramatically reducing parsing errors.
  • Type Safety: The output is not just valid JSON, but also adheres to the data types defined in your schema.
  • Reduced Development Time: No more writing custom parsing and validation logic.
  • Increased Reliability: Consistent, predictable output makes your applications more robust.

How to Call It

You can interact with the Structured Output MCP Agent using either streamable-http for direct HTTP requests or A2A (Agent-to-Agent) messaging for more complex agent orchestrations.

The agent's MCP endpoint is: https://fastmcp-instructor-72225f.getvda.ai/mcp

Using Streamable-HTTP

For direct HTTP requests, you'll send a POST request to the MCP endpoint with a JSON body.

Example Request:

{
  "method": "structured_output",
  "params": {
    "prompt": "Extract the user's name, their preferred contact method (email or phone), and the message they want to send.",
    "schema": {
      "type": "object",
      "properties": {
        "user_name": { "type": "string", "description": "The full name of the user" },
        "contact_method": { "type": "string", "enum": ["email", "phone"], "description": "Preferred contact method" },
        "message": { "type": "string", "description": "The message to send" }
      },
      "required": ["user_name", "contact_method", "message"]
    },
    "user_input": "My name is Alice Wonderland, you can reach me at alice@example.com. I'd like to inquire about the new features."
  }
}
Enter fullscreen mode Exit fullscreen mode

Example Response:

{
  "result": {
    "user_name": "Alice Wonderland",
    "contact_method": "email",
    "message": "I'd like to inquire about the new features."
  }
}
Enter fullscreen mode Exit fullscreen mode

Using A2A (message/send)

For agent-to-agent communication, you'd use the message/send method, encapsulating the structured_output call within the payload.

Example Request (A2A):

{
  "method": "message/send",
  "params": {
    "recipient_did": "did:vda:fastmcp-instructor-72225f.getvda.ai",
    "payload": {
      "method": "structured_output",
      "params": {
        "prompt": "Extract the user's name, their preferred contact method (email or phone), and the message they want to send.",
        "schema": {
          "type": "object",
          "properties": {
            "user_name": { "type": "string", "description": "The full name of the user" },
            "contact_method": { "type": "string", "enum": ["email", "phone"], "description": "Preferred contact method" },
            "message": { "type": "string", "description": "The message to send" }
          },
          "required": ["user_name", "contact_method", "message"]
        },
        "user_input": "My name is Bob The Builder. Please call me at 555-1234 to discuss the project."
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Example Response (A2A - simplified, actual response includes A2A envelope):

{
  "result": {
    "user_name": "Bob The Builder",
    "contact_method": "phone",
    "message": "to discuss the project."
  }
}
Enter fullscreen mode Exit fullscreen mode

Discovery and Metering

You can discover the capabilities of this agent (and others) by using the initialize and tools/list methods, which are free to call. Agent execution, including the structured_output method, is metered via Nevermined x402 micropayments. This ensures fair usage and sustainable operation of the agent ecosystem.

Start building more robust and intelligent applications today by integrating the Structured Output MCP Agent!

https://agents.getvda.ai/agents

Top comments (0)