Skip to content

[codex] Validate tool inputs before execution#49

Open
germanescobar wants to merge 1 commit into
mainfrom
codex/validate-tool-inputs
Open

[codex] Validate tool inputs before execution#49
germanescobar wants to merge 1 commit into
mainfrom
codex/validate-tool-inputs

Conversation

@germanescobar
Copy link
Copy Markdown
Owner

Summary

Adds defensive validation for registered tool inputs before a tool is executed. The registry now checks required fields and primitive property types from the tool JSON schema, returning a structured tool error when model output is malformed.

The executor now validates before policy evaluation, so a malformed run_command call like {} returns a clear tool result instead of reaching the command policy path and crashing on input.command.trim().

Root Cause

Tool schemas advertised required fields, but the runner trusted model-provided input and passed malformed objects through to policy and tool execution. For run_command, the default policy assumed input.command was a string and trimmed it directly.

Impact

Malformed tool calls now stay inside the normal tool-result flow. The model receives an actionable error such as Invalid input for tool "run_command": missing required field "command"., and the run can continue instead of crashing the tool runner.

Validation

  • npm run build
  • npm test

@germanescobar germanescobar marked this pull request as ready for review June 6, 2026 01:19
@germanescobar
Copy link
Copy Markdown
Owner Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7980123e9b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/tools/registry.ts

for (const field of required) {
if (
!Object.prototype.hasOwnProperty.call(input, field) ||
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard non-object tool inputs before required checks

When a provider returns a malformed function call whose arguments parse to null, the OpenAI adapters currently cast JSON.parse(...) directly to Record<string, unknown> (for example in src/models/openai-responses.ts:327 and src/models/openai.ts:275). This new validation path then calls hasOwnProperty on that value and throws TypeError before the executor can return the structured validation tool result, so that malformed tool call still aborts the run instead of letting the model recover.

Useful? React with 👍 / 👎.

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