Skip to content

Conversation

@huynguyen03dev
Copy link
Contributor

Problem

OpenAI's strict schema validation rejects tool schemas where array properties lack an items definition:

Invalid schema for function 'tb__ask_user': In context=('properties', 'options'), array schema missing items.

Solution

Add FixCodexToolSchemas() utility that automatically adds items: {} to any array-typed schema missing it before sending requests to the Codex API.

Changes

  • New: internal/util/codex_schema.go - Schema fixing utility
  • New: internal/util/codex_schema_test.go - Unit tests
  • Modified: internal/runtime/executor/codex_executor.go - Apply fix before sending requests

Testing

  • 4 unit tests covering basic case, existing items preservation, anyOf nesting, and no-tools passthrough
  • Manually tested with Amp CLI proxied through CLIProxyAPI

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @huynguyen03dev, 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 implements a crucial fix to ensure compatibility with OpenAI's strict schema validation for Codex tool parameters. It introduces a new utility that proactively modifies tool schemas by adding a default items definition to any array properties that lack one, thereby preventing API request rejections and improving the robustness of interactions with the Codex API.

Highlights

  • Problem Resolution: Addresses OpenAI's strict schema validation for Codex tool parameters, which previously rejected schemas missing 'items' definitions for array properties.
  • New Utility: Introduces FixCodexToolSchemas() in internal/util/codex_schema.go to automatically inject items: {} into array-typed schemas before API requests.
  • Integration: The new utility is applied in internal/runtime/executor/codex_executor.go to ensure all outgoing Codex API requests conform to the required schema.
  • Comprehensive Testing: Includes new unit tests in internal/util/codex_schema_test.go covering various scenarios, along with manual testing.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 a utility function, FixCodexToolSchemas, to automatically add a missing items property to array schemas in tool parameters before sending requests to the Codex API. This change addresses a strict schema validation requirement from OpenAI. The fix is applied in both Execute and ExecuteStream methods of the CodexExecutor. The new utility is well-tested with a comprehensive suite of unit tests covering various scenarios. The overall implementation is solid. I've included one suggestion to refactor a recursive function for improved performance and readability.

Comment on lines +78 to +104
func findArrayTypePaths(node gjson.Result, path string) []string {
var paths []string

if node.IsObject() {
if isArrayType(node) {
paths = append(paths, path)
}
node.ForEach(func(key, value gjson.Result) bool {
newPath := key.String()
if path != "" {
newPath = path + "." + key.String()
}
paths = append(paths, findArrayTypePaths(value, newPath)...)
return true
})
} else if node.IsArray() {
for i, elem := range node.Array() {
newPath := strconv.Itoa(i)
if path != "" {
newPath = path + "." + strconv.Itoa(i)
}
paths = append(paths, findArrayTypePaths(elem, newPath)...)
}
}

return paths
}
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 recursive implementation of findArrayTypePaths can be inefficient due to the use of append(slice, anotherSlice...) within the recursion. Each call creates a new slice, leading to multiple allocations. A more performant and arguably clearer approach is to use a closure to append to a single paths slice, avoiding the overhead of repeated slice allocations.

// findArrayTypePaths recursively finds all paths where type="array".
func findArrayTypePaths(node gjson.Result, path string) []string {
	var paths []string
	var find func(gjson.Result, string)

	find = func(n gjson.Result, p string) {
		if n.IsObject() {
			if isArrayType(n) {
				paths = append(paths, p)
			}
			n.ForEach(func(key, value gjson.Result) bool {
				childPath := key.String()
				if p != "" {
					childPath = p + "." + childPath
				}
				find(value, childPath)
				return true
			})
		} else if n.IsArray() {
			for i, elem := range n.Array() {
				childPath := strconv.Itoa(i)
				if p != "" {
					childPath = p + "." + childPath
				}
				find(elem, childPath)
			}
		}
	}

	find(node, path)
	return paths
}

OpenAI's strict schema validation rejects array-typed schemas without
an 'items' definition. This fix adds 'items: {}' to any array schema
missing it before sending requests to the Codex API.

Fixes error: Invalid schema for function 'tb__ask_user': In
context=('properties', 'options'), array schema missing items.

Co-authored-by: Amp <[email protected]>
@huynguyen03dev huynguyen03dev force-pushed the fix/codex-array-schema-missing-items branch from 908f240 to f7100c8 Compare January 28, 2026 05:45
@huynguyen03dev
Copy link
Contributor Author

@luispater can you take a look at this problem? This also happens when using amp deepmode, and forward the request to amp without mapping.

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