Skip to content

Conversation

@aibysid
Copy link

@aibysid aibysid commented Nov 13, 2025

  • Add agentStructuredOutput input parameter matching LLM Node structure
  • Implement configureStructuredOutput method to convert schema to Zod
  • Add createZodSchemaFromJSON helper for complex JSON schemas
  • Configure structured output before binding tools (required order)
  • Disable streaming when structured output is enabled
  • Extract structured fields in prepareOutputObject method
  • Resolves issue Agent Node - Add structured JSON response (similar to LLM Node) #5256
Screenshot 2025-11-13 at 13 47 08

- Add agentStructuredOutput input parameter matching LLM Node structure
- Implement configureStructuredOutput method to convert schema to Zod
- Add createZodSchemaFromJSON helper for complex JSON schemas
- Configure structured output before binding tools (required order)
- Disable streaming when structured output is enabled
- Extract structured fields in prepareOutputObject method
- Resolves issue FlowiseAI#5256
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @aibysid, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant enhancement to the Agent Node by adding robust support for structured JSON output. Users can now define a desired JSON schema for the agent's responses, which is then converted into a Zod schema for validation and enforcement. This feature provides greater control over the format of agent outputs, improving integration with downstream systems and ensuring predictable data structures.

Highlights

  • Structured Output Input: Added 'agentStructuredOutput' parameter to the Agent Node for defining JSON output schemas.
  • Zod Schema Conversion: Implemented 'configureStructuredOutput' to convert user-defined schemas into Zod schemas.
  • Complex JSON Schema Support: Introduced 'createZodSchemaFromJSON' helper for handling intricate nested JSON schemas.
  • Execution Order: Ensured structured output configuration occurs before tool binding.
  • Streaming Disabled: Streaming is automatically disabled when structured output is active.
  • Output Extraction: Structured fields are now extracted and included in the final output object.
  • Issue Resolution: Addresses and resolves issue Agent Node - Add structured JSON response (similar to LLM Node) #5256.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces structured JSON output capabilities to the Agent node, which is a great feature. The implementation correctly disables streaming when this feature is active and adds the necessary UI and backend logic to build a Zod schema from user input. My review focuses on improving the robustness and clarity of the new schema generation logic. I've identified an issue with how empty enums are handled, found an unreachable code block that should be removed, and suggest documenting a custom feature to make it usable for end-users.

Comment on lines +1776 to +1785
} else if (Array.isArray(value)) {
// Array values without a type property
if (value.length > 0) {
// If the array has items, recursively create a schema for the first item
const itemSchema = this.createZodSchemaFromJSON(value[0])
schemaObj[key] = z.array(itemSchema)
} else {
// Empty array, allow any array
schemaObj[key] = z.array(z.any())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This else if block is unreachable because its condition Array.isArray(value) contradicts the parent if condition on line 1736, which requires !Array.isArray(value). This dead code appears to be a duplicate of the logic on lines 1790-1799 and should be removed to improve code clarity.

}
}
}`,
description: 'JSON schema for the structured output',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The description for jsonSchema is missing important information about a custom feature. The implementation allows marking fields as optional using a non-standard "optional": true property inside a field's definition. This should be documented here to make the feature discoverable and usable for users.

For example, you could update the description to:
JSON schema for the structured output. To mark a field as optional, add "optional": true to its definition.

Comment on lines +1684 to +1687
const enumValues = sch.enumValues?.split(',').map((item: string) => item.trim()) || []
zodObj[sch.key] = z
.enum(enumValues.length ? (enumValues as [string, ...string[]]) : ['default'])
.describe(sch.description || '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation for enum types has a potentially confusing fallback. If a user selects the enum type but leaves enumValues empty, the schema defaults to z.enum(['default']). This forces the model to output the literal string "default", which is likely not the user's intent and can be difficult to debug. It would be more robust to throw an error if enumValues is empty for an enum type, providing clear feedback to the user about the missing configuration.

Suggested change
const enumValues = sch.enumValues?.split(',').map((item: string) => item.trim()) || []
zodObj[sch.key] = z
.enum(enumValues.length ? (enumValues as [string, ...string[]]) : ['default'])
.describe(sch.description || '')
const enumValues = sch.enumValues?.split(',').map((item: string) => item.trim()).filter(Boolean) || [];
if (enumValues.length === 0) {
throw new Error(`Enum values for key "${sch.key}" cannot be empty when type is "enum".`);
}
zodObj[sch.key] = z.enum(enumValues as [string, ...string[]]).describe(sch.description || '');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant