Skip to content

fix(checks)!: make Interact injection name-based#2302

Merged
kevinmessiaen merged 3 commits intomainfrom
2291-bug-output-generator-does-not-receive-trace-if-typed-as-optional-2
Mar 17, 2026
Merged

fix(checks)!: make Interact injection name-based#2302
kevinmessiaen merged 3 commits intomainfrom
2291-bug-output-generator-does-not-receive-trace-if-typed-as-optional-2

Conversation

@kevinmessiaen
Copy link
Copy Markdown
Member

@kevinmessiaen kevinmessiaen commented Mar 12, 2026

Description

Replace the old type-based parameter injection with a name-based injectable for inputs and trace, simplifying the code and fixing issues due to type hint inspection

Breaking changes

When passing inputs/outpus function to Interact, the signature must match inputs and trace variable name for injection mapping to work. Previously it was based on type hint.

Related Issue

Fixes #2291

Replace the old type-based parameter injection with a name-based injectable for
`inputs` and `trace`, supporting kw-only/pos-only/optional parameters and failing
fast when required params are not injectable.

Made-with: Cursor
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly refactors the parameter injection mechanism within the Interact class, moving from a type-based system to a more robust and explicit name-based injection. This change aims to simplify the underlying code, enhance maintainability, and address existing issues where type hint inspection caused problems. The new approach provides clearer control over how parameters like inputs and trace are resolved and passed to user-defined functions, making the system more predictable and less prone to runtime errors.

Highlights

  • Name-based Parameter Injection: Replaced the previous type-based parameter injection mechanism with a new name-based approach for inputs and trace within the Interact class, improving flexibility and resolving issues related to type hint inspection.
  • New Injection Utilities: Introduced ValueProvider and ValueGenerator classes to handle the new name-based injection logic, centralizing parameter resolution and simplifying the Interact class implementation.
  • Refactored Interact Class: The Interact class was updated to utilize the new ValueProvider and ValueGenerator for managing inputs and outputs, leading to cleaner and more maintainable code.
  • Improved Test Coverage: Added new test cases to validate the behavior of name-based injection, including scenarios with keyword-only and positional-only parameters, and updated existing tests to reflect the new validation logic.

🧠 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.

Changelog
  • libs/giskard-checks/README.md
    • Updated example target_sut lambda parameter from x to inputs for consistency.
  • libs/giskard-checks/src/giskard/checks/core/interaction/interact.py
    • Removed imports for ParameterInjectionRequirement and ValueGeneratorProvider.
    • Added imports for new ValueGenerator and ValueProvider from giskard.checks.utils.injectable.
    • Removed INJECTABLE_TRACE and INJECTABLE_INPUT constants.
    • Replaced _input_value_generator_provider with ValueGenerator using name-based injection for trace.
    • Replaced _output_value_provider with _output_injectable using ValueProvider for inputs and trace.
    • Modified calls to _input_value_generator_provider and _output_injectable to pass arguments as keyword arguments.
  • libs/giskard-checks/src/giskard/checks/utils/injectable.py
    • Added new file containing _validate_kwargs_keys function for parameter validation.
    • Added ValueProvider class for name-based parameter injection to callables.
    • Added ValueGenerator class for name-based parameter injection to generator callables.
  • libs/giskard-checks/src/giskard/checks/utils/parameter_injection.py
    • Removed file, deprecating the old type-based parameter injection system.
  • libs/giskard-checks/src/giskard/checks/utils/value_provider.py
    • Removed file, deprecating the old value provider system.
  • libs/giskard-checks/tests/core/test_scenario.py
    • Updated echo_sut and echo_upper_sut lambda parameters from x to inputs.
  • libs/giskard-checks/tests/core/test_suite.py
    • Updated sut1, sut2, sut3, identity_sut, and callable_suite lambda parameters from x to inputs.
  • libs/giskard-checks/tests/trace/test_interaction.py
    • Added new test cases for outputs functions with keyword-only and positional-only inputs and trace parameters.
    • Modified test cases to reflect that unmapped required parameters now raise TypeError during validation.
    • Added test cases for inputs functions with keyword-only and positional-only trace parameters.
    • Added test cases for inputs and outputs functions with optional trace parameters.
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
Copy Markdown
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 refactors the parameter injection mechanism by introducing a new injectable.py module, which defines ValueProvider and ValueGenerator classes. These new classes replace the previous ParameterInjectionRequirement, CallableInjectionMapping, and ValueGeneratorProvider structures, simplifying how parameters are injected into callables. The Interact class in interact.py is updated to use this new injection system, including changes to how input and output value providers are initialized and called, now expecting keyword arguments. Corresponding test files and README examples are updated to reflect the new inputs parameter naming convention and to include new test cases for keyword-only and positional-only parameters, ensuring the updated injection logic correctly handles various function signatures.

@kevinmessiaen kevinmessiaen self-assigned this Mar 13, 2026
Copy link
Copy Markdown
Member

@Inokinoki Inokinoki left a comment

Choose a reason for hiding this comment

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

LGTM.

Just that when I ran tests, it's saying that I did not enable the asyncio for pytest. Adding this fixes it:

[tool.pytest.ini_options]
asyncio_mode = "auto"
markers = [

Checking with the tests and the ways to use it now ;)

@kevinmessiaen kevinmessiaen requested a review from Inokinoki March 16, 2026 04:17
@kevinmessiaen
Copy link
Copy Markdown
Member Author

LGTM.

Just that when I ran tests, it's saying that I did not enable the asyncio for pytest. Adding this fixes it:

[tool.pytest.ini_options]
asyncio_mode = "auto"
markers = [

Checking with the tests and the ways to use it now ;)

I added te config to root pyproject, should be good now. Thanks for the review

@kevinmessiaen kevinmessiaen merged commit 42af711 into main Mar 17, 2026
23 checks passed
@kevinmessiaen kevinmessiaen deleted the 2291-bug-output-generator-does-not-receive-trace-if-typed-as-optional-2 branch March 17, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Bug: output generator does not receive trace if typed as optional

2 participants