Skip to content

fix: Implement missing run_moderation method in PromptGuardSafetyImpl#3101

Merged
ashwinb merged 1 commit intollamastack:mainfrom
Elbehery:20250812_fix_PromptGuardSafetyImpl_abstract_class_instantiate
Aug 12, 2025
Merged

fix: Implement missing run_moderation method in PromptGuardSafetyImpl#3101
ashwinb merged 1 commit intollamastack:mainfrom
Elbehery:20250812_fix_PromptGuardSafetyImpl_abstract_class_instantiate

Conversation

@Elbehery
Copy link
Contributor

What does this PR do?

This PR addresses an issue where PromptGuardSafetyImpl was an incomplete implementation of an abstract class. The class was missing the required run_moderation method from its parent interface.

Currently, running pre-commit locally fails with the error below.

llama_stack/providers/inline/safety/prompt_guard/__init__.py:15: error: Cannot instantiate abstract class "PromptGuardSafetyImpl" with abstract attribute "run_moderation"  [abstract]
Found 1 error in 1 file (checked 410 source files)

This PR fixes the issue as follows

  • Added the missing run_moderation method to PromptGuardSafetyImpl
  • Method raises NotImplementedError with appropriate message indicating this functionality is not implemented for PromptGuard
  • This allows the class to be properly instantiated while clearly indicating the limitation

Copy link
Contributor

@nathan-weinberg nathan-weinberg left a comment

Choose a reason for hiding this comment

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

Strange as pre-commit was passing in #2678 which was the last PR to modify this file

Thanks for the fix!

Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
@Elbehery Elbehery force-pushed the 20250812_fix_PromptGuardSafetyImpl_abstract_class_instantiate branch from 28a1cce to eef61e2 Compare August 12, 2025 11:08
Copy link
Contributor

@ashwinb ashwinb left a comment

Choose a reason for hiding this comment

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

thx

@ashwinb
Copy link
Contributor

ashwinb commented Aug 12, 2025

cc @slekkala1

@ashwinb ashwinb merged commit 4a13ef4 into llamastack:main Aug 12, 2025
31 checks passed
@r3v5
Copy link
Contributor

r3v5 commented Aug 12, 2025

Hey @Elbehery! I pulled from main, did rebase on my branch and still have this issue:

git commit -m "refactor: modify DELETE API endpoints by returning HTTP 204 No Content + empty body instead of 200 OK + response body with null"                                                                                                                                 ─╯
check for merge conflicts....................................................Passed
trim trailing whitespace.................................(no files to check)Skipped
check for added large files..................................................Passed
fix end of files.............................................................Passed
don't commit to branch.......................................................Passed
check yaml...............................................(no files to check)Skipped
detect private key...........................................................Passed
mixed line ending............................................................Passed
check that executables have shebangs.....................(no files to check)Skipped
check json...............................................(no files to check)Skipped
check that scripts with shebangs are executable..............................Passed
check for broken symlinks................................(no files to check)Skipped
check toml...............................................(no files to check)Skipped
Insert license in comments...................................................Passed
ruff (legacy alias)..........................................................Passed
ruff format..................................................................Passed
blacken-docs.................................................................Passed
uv-lock..................................................(no files to check)Skipped
mypy.........................................................................Failed
- hook id: mypy
- exit code: 1

llama_stack/providers/inline/safety/prompt_guard/__init__.py:15: error: Cannot instantiate abstract class "PromptGuardSafetyImpl" with abstract attribute "run_moderation"  [abstract]
Found 1 error in 1 file (checked 403 source files)

Distribution Template Codegen............................(no files to check)Skipped
Provider Codegen.........................................(no files to check)Skipped
API Spec Codegen.........................................(no files to check)Skipped
Check GitHub Actions use SHA-pinned actions..................................Passed
Check for missing __init__.py files..........................................Passed
Block @pytest.mark.asyncio and @pytest_asyncio.fixture.......................Passed
Generate CI documentation................................(no files to check)Skipped

╭─    ~/GitHub/llama-stack    modify-delet…eturning-204 *4 +2 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 1 ✘  3s     16:39:57  ─╮
╰─      

@r3v5
Copy link
Contributor

r3v5 commented Aug 12, 2025

Alright, it works now!

@Elbehery Elbehery deleted the 20250812_fix_PromptGuardSafetyImpl_abstract_class_instantiate branch August 13, 2025 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants