Skip to content

feat: Better support for tools_strict=True when using the OpenAIChatGenerator #9382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

sjrl
Copy link
Contributor

@sjrl sjrl commented May 13, 2025

Related Issues

Proposed Changes:

Added _strictify_function_schema function to enforce OpenAI's strict schema for tool specifications. This update affects the OpenAIChatGenerator component when tools_strict=True is enabled.

This function:

  • recursively go through the parameters schema, find all type="object" schemas and add additionalProperties=False or remove it if it has no-required parameters
  • recursively go through the parameter schema and remove any type: "object" parameters that don't have any required params --> this is not supported in strict mode

TODO:

  • After removing all parameters have the schema {"type": "object", "additionalProperties": True} need to repair the remaining schema in case one of those removed parameters is a required parameter elsewhere. Look at test_strictify_function_schema_chat_message in test_openai.py to see a relevant example when ChatMessage is in the function schema.

How did you test it?

  • Added new integration test

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct
  • I have updated the related issue with new insights and changes
  • I added unit tests and updated the docstrings
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I documented my code
  • I ran pre-commit hooks and fixed any issue

@github-actions github-actions bot added topic:tests type:documentation Improvements on the docs labels May 13, 2025
@sjrl sjrl self-assigned this May 13, 2025
@coveralls
Copy link
Collaborator

coveralls commented May 13, 2025

Pull Request Test Coverage Report for Build 15132598341

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 15 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.03%) to 90.42%

Files with Coverage Reduction New Missed Lines %
core/pipeline/async_pipeline.py 3 67.32%
components/generators/chat/openai.py 12 94.26%
Totals Coverage Status
Change from base Build 15117961888: -0.03%
Covered Lines: 10977
Relevant Lines: 12140

💛 - Coveralls

@sjrl sjrl changed the title feat: Better support for tools_strict=True when using the OpenAIChatGenerator feat: Better support for tools_strict=True when using the OpenAIChatGenerator May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic:tests type:documentation Improvements on the docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Better support for tools_strict=True when using the OpenAIChatGenerator
2 participants