Skip to content

refactor(giskard-checks)!: remove Scenario.from_sequence#2325

Merged
henchaves merged 3 commits intomainfrom
chore/improve-scenario-builder
Mar 25, 2026
Merged

refactor(giskard-checks)!: remove Scenario.from_sequence#2325
henchaves merged 3 commits intomainfrom
chore/improve-scenario-builder

Conversation

@kevinmessiaen
Copy link
Copy Markdown
Member

Use Scenario(name=...).extend(...) instead. Update README and tests.

Use Scenario(name=...).extend(...) instead. Update README and tests.

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 streamlines the Scenario object creation API by deprecating and removing the from_sequence class method. The change promotes a more consistent and fluent interface for building scenarios using the extend instance method, simplifying the codebase and improving developer experience. The refactoring includes updates to documentation and comprehensive test coverage to align with the new API.

Highlights

  • API Refactoring: The Scenario.from_sequence class method has been removed, standardizing scenario construction to use Scenario(...).extend(...).
  • Documentation and Examples Update: The README.md file has been updated to reflect the new extend method usage in code examples.
  • Test Suite Modernization: All relevant test cases have been updated to utilize the extend method, ensuring consistency with the new API.

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

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

The pull request refactors the Scenario class by removing the from_sequence class method. All existing usages of Scenario.from_sequence in documentation, core logic, and test files have been updated to use the Scenario(...).extend(...) fluent API. This change consolidates scenario initialization parameters like name and trace_type into the Scenario constructor, simplifying the extend method's role to solely adding components. Corresponding test class and function names were also updated to reflect this API change.

Comment on lines +555 to 559
scenario = Scenario(name="programmatic_scenario").extend(
Interact(inputs="Hello", outputs=lambda inputs: "Hi"),
Equals(expected_value="Hi", key="trace.last.outputs"),
name="programmatic_scenario",
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This change replaces Scenario.from_sequence with Scenario(name=...).extend(...), which aligns with the refactoring goal. This change improves the readability and maintainability of the code by using a more fluent and intuitive API for creating scenarios.

Comment on lines +1019 to +1020
class TestScenarioExtendAndSerialization:
"""Test Scenario.extend() and step-based serialization."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Renaming the test class to TestScenarioExtendAndSerialization accurately reflects the focus on testing the extend method and serialization, aligning with the refactoring changes.

Comment on lines +1047 to +1048
async def test_extend_with_only_checks(self):
"""extend handles scenario starting with checks only."""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Renaming the test function to test_extend_with_only_checks accurately reflects the test's purpose, which is to verify that the extend method correctly handles scenarios starting with checks only.

Comment on lines +94 to +97
scenario = Scenario[Any, Any, MessageTraces](
name="test_single_message",
trace_type=MessageTraces,
).extend(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The change from using Scenario[Any, Any, MessageTraces].from_sequence to Scenario[Any, Any, MessageTraces](...).extend(...) aligns with the refactoring goal of removing from_sequence and using extend for scenario creation. Initializing name and trace_type directly in the Scenario constructor improves code clarity.

Comment on lines 125 to 126
expected_value="Hello, I want to apply for a job.",
key="trace.interactions[-1].metadata['tests.integration.test_stateless.mock_apply_tool']['call_args'].args[1]",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Removing the name and trace_type parameters from the extend call is consistent with the refactoring, as these parameters are now handled in the Scenario constructor. This change simplifies the extend call and makes the code more readable.

@henchaves henchaves merged commit 3bd0d42 into main Mar 25, 2026
23 checks passed
@henchaves henchaves deleted the chore/improve-scenario-builder branch March 25, 2026 15:41
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.

2 participants