Skip to content

feat: Add granite guardian filter - #200

Open
OscarDDD wants to merge 11 commits into
mainfrom
Add_Granite_Guardian_Filter
Open

OscarDDD wants to merge 11 commits into
mainfrom
Add_Granite_Guardian_Filter

Conversation

@OscarDDD

@OscarDDD OscarDDD commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Context

Closes SAP/ai-sdk-python-backlog#56.

What this PR does and why it is needed

This PR adds IBM Granite Guardian 4.1 as a new self-hosted content filter provider for the content filtering module, alongside the existing Azure Content Safety and Llama Guard 3 providers. Unit tests, integration tests are also included.

Definition of Done

  • Code is tested (Unit, Integration, E2E)
  • Error handling created / updated & covered by the tests above
  • Documentation updated
    • Only Public APIs are allowed to be used in documentation/tutorials/sample code
  • (Optional) Aligned changes with the JS/TS and Java SDK
  • (Optional) Release notes updated -->

@OscarDDD OscarDDD self-assigned this Oct 21, 2026
@OscarDDD
OscarDDD marked this pull request as ready for review October 21, 2026 15:29

@mwien mwien left a comment

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.

Do you have tests with enable_reasoning = True especially in integration/e2e tests or sample code?

Apart from that just small nitpicks (see below).

"""
Content criteria to evaluate.

Note: Granite Guardian requires separate calls for each configured content category.

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.

[pp] Maybe "Granite Guardian performs separate calls for each configured content category." is clearer in case that is meant. "requires" sounds a bit like the user has to call it multiple times.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is resolved in the latest version.


class GraniteGuardian41Categories(BaseModel):
"""
Content criteria to evaluate.

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.

[pp] mention Granite Guardian in docstring.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is resolved in the latest version.

@OscarDDD
OscarDDD requested a review from mwien October 30, 2026 08:33

@yamaceay yamaceay left a comment

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.

everything is in place, just small comments

from gen_ai_hub.orchestration_v2.models.base import ABCBaseModel as BaseModel


class GraniteGuardian41Categories(BaseModel):

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.

[req] spec enforces minProperties: 1, I would like to know whether it would be a good practice to add Pydantic validation to this class: it should have at least one of them to be set to True. Maybe one test case with empty initialization would be nice too, it should fail if every category is False.

@OscarDDD OscarDDD Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The idea of current implementation is to follow the same schema as the LlamaGuard38bFilter, where minProperties: 1 also required. The server also accepts the all false situations.

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.

Hm, I get that it is a general pattern. Would still make sense to add a @model_validator function for these classes (if not use a common validator for these)? If minProperties: 1 is set in spec and server accepts zero, it's weird and unintended so far as I understood.

@OscarDDD OscarDDD Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ah, I see the points. I understand minProperties: 1 only requires the object to contain at least one required keys — it counts keys, not values, so an all-false config still satisfies it (the keys are present), whereas an empty {} is rejected.

This branch has not been deployed

No deployments
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.

3 participants