Skip to content

refactor!: remove Safety/Shields API and all connected code#5291

Draft
leseb wants to merge 34 commits intollamastack:mainfrom
leseb:remove-safety-api
Draft

refactor!: remove Safety/Shields API and all connected code#5291
leseb wants to merge 34 commits intollamastack:mainfrom
leseb:remove-safety-api

Conversation

@leseb
Copy link
Copy Markdown
Collaborator

@leseb leseb commented Mar 25, 2026

Summary

Remove the Safety/Shields API and all connected code. Shields are already marked deprecated in the spec. Safety enforcement is better handled at the platform level (guardrails orchestrators, NeMo Guardrails).

What was removed

  • Safety and Shields API packages
  • All safety providers (llama-guard, prompt-guard, code-scanner, bedrock, nvidia, sambanova, passthrough)
  • Guardrail execution code from the agent/responses loop
  • All distribution config references
  • All integration and unit tests

Stats

  • 149 files changed, -10,642 lines net
  • 226 unit tests pass

Test plan

  • Unit tests pass
  • CI

Signed-off-by: Sebastien Han shan@redhat.com

Remove the deprecated Safety and Shields APIs entirely from llama-stack.
This includes:

- API packages (llama_stack_api/safety/, llama_stack_api/shields/)
- Provider implementations (inline: llama-guard, prompt-guard, code-scanner;
  remote: bedrock, nvidia, sambanova, passthrough)
- Provider registry (providers/registry/safety.py)
- Router and routing table (core/routers/safety.py, core/routing_tables/shields.py)
- Api enum values (Api.safety, Api.shields)
- SafetyConfig, ShieldWithOwner, ShieldsProtocolPrivate from core datatypes
- Distribution YAML configs (safety providers, shields registered resources,
  safety config sections, run-with-safety.yaml files)
- Distribution template code (get_shield_registry, default_shields, safety_config)
- Agent/responses guardrail execution code (run_guardrails, extract_guardrail_ids,
  safety_api parameter threading, input/output guardrail checks in streaming)
- Telemetry helpers and constants for safety
- All safety-related unit and integration tests
- ShieldToModerationMixin utility

The guardrails parameter in create_openai_response is preserved in the
signature but is now a no-op. The Responses API continues to work without
safety.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 25, 2026
@leseb leseb added this to the 0.8.0 milestone Mar 25, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

✱ Stainless preview builds

This PR will update the llama-stack-client SDKs with the following commit message.

refactor!: remove Safety/Shields API and all connected code

Edit this comment to update it. It will appear in the SDK's changelogs.

llama-stack-client-go studio · conflict

Your SDK build had a "fatal" conclusion in the base build, which improved to "merge_conflict", but this did not represent a regression.

llama-stack-client-python studio · conflict

Your SDK build had at least one new note diagnostic, which is a regression from the base state.

New diagnostics (6 note)
💡 Model/Recommended: `#/components/schemas/ChatCompletionMessageToolCall` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat`.
💡 Model/Recommended: `#/components/schemas/OpenAIFile` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIFileFile` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAISystemMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIToolMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIDeveloperMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
llama-stack-client-openapi studio · code · diff

Your SDK build had at least one "warning" diagnostic, but this did not represent a regression.
generate ⚠️

New diagnostics (6 note)
💡 Model/Recommended: `#/components/schemas/ChatCompletionMessageToolCall` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat`.
💡 Model/Recommended: `#/components/schemas/OpenAIFile` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIFileFile` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAISystemMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIToolMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIDeveloperMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
llama-stack-client-node studio · conflict

Your SDK build had at least one new note diagnostic, which is a regression from the base state.

New diagnostics (6 note)
💡 Model/Recommended: `#/components/schemas/ChatCompletionMessageToolCall` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat`.
💡 Model/Recommended: `#/components/schemas/OpenAIFile` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIFileFile` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAISystemMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIToolMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.
💡 Model/Recommended: `#/components/schemas/OpenAIDeveloperMessageParam` could potentially be defined as a [model](https://www.stainless.com/docs/guides/configure#models) within `#/resources/chat/subresources/completions`.

This comment is auto-generated by GitHub Actions and is automatically kept up to date as you push.
If you push custom code to the preview branch, re-run this workflow to update the comment.
Last updated: 2026-04-01 20:40:44 UTC

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 25, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Mar 25, 2026
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify mergify bot removed the needs-rebase label Mar 25, 2026
leseb and others added 3 commits March 25, 2026 18:09
Signed-off-by: Sébastien Han <seb@redhat.com>
Resolve merge conflicts from upstream/main, primarily around the
agents-to-responses API rename (PR llamastack#5195) and new upstream changes.
The key resolutions were updating Api.agents to Api.responses in
datatypes.py and resolver.py, removing reintroduced safety/shields
references from OCI and WatsonX distributions, fixing the stainless
config to remove safety/shields/moderations endpoints, and
regenerating all OpenAPI specs, distribution configs, and coverage
documentation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Merge upstream/main into remove-safety-api, resolving conflicts by
keeping the safety API removal from this branch. All modify/delete
conflicts for safety-related files (shields, safety providers, safety
router, safety registry) were resolved by accepting the deletion.
Content conflicts in core/datatypes.py, core/stack.py,
distributions/template.py, and llama_stack_api/datatypes.py were
resolved by removing the safety-related code (ShieldWithOwner,
ShieldsProtocolPrivate, validate_safety_config, get_shield_registry)
that upstream had modified but this branch intentionally removes.

Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 26, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Mar 26, 2026
leseb and others added 2 commits March 26, 2026 21:23
Accept upstream's updated OpenAI API conformance data including the new
Moderations category and updated summary statistics (28/146 endpoints,
87.8% conformance score). These are auto-generated documentation files
tracking OpenAI API coverage which are unrelated to the Llama Stack
Safety/Shields API removal in this branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
The pre-commit hook regenerated conformance data to reflect the actual
endpoints available in this branch (27/146 endpoints, 89.0% conformance
score) since the Moderations endpoint is not present after the Safety
API removal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify mergify bot removed the needs-rebase label Mar 26, 2026
leseb added a commit to leseb/llama-stack that referenced this pull request Mar 27, 2026
- Add "agentic" to tagline per franciscojavierarceo suggestion
- Remove Safety/Moderations (being removed in llamastack#5291)
- Use uv instead of pip in install instructions
- Remove Swift and Kotlin from SDK table
- Fix "semantic search" to just "search" for vector stores
- Mention non-OpenAI APIs (Prompts, File Processors)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
leseb and others added 3 commits March 27, 2026 11:53
Resolve modify/delete conflicts for dell distribution files that were
deleted upstream. Accept the upstream deletion since the dell distribution
was removed in main.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Resolve merge conflicts in generated conformance documentation files
(conformance.mdx and openai-coverage.json) by accepting upstream values
and letting the pre-commit hook regenerate with the correct scores for
this branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
leseb and others added 2 commits March 30, 2026 15:10
Resolve merge conflicts from upstream splitting test_openai_responses.py
into smaller focused modules. The split file was deleted (upstream) and
modified (this branch), so we accept the upstream deletion since the new
split files are present. Remove safety_api references from the new test
files to align with this branch's removal of the Safety API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 30, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Mar 30, 2026
Resolve merge conflicts from upstream safety-related changes (guardrails,
validate_safety_config, safety routers and providers) by keeping them
deleted, consistent with this branch's goal of removing the Safety/Shields
API entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify mergify bot removed the needs-rebase label Mar 30, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 30, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Mar 30, 2026
leseb and others added 2 commits March 30, 2026 16:43
Merge upstream/main into remove-safety-api branch, resolving conflicts in
spec files by keeping the Safety/Shields API removal from this branch and
discarding the moderations and shields endpoints that upstream added.

Signed-off-by: Sebastien Han <seb@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Regenerate the stainless OpenAPI specs to reflect the current state of
the codebase after merging upstream/main.

Signed-off-by: Sebastien Han <seb@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify mergify bot removed the needs-rebase label Mar 30, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Mar 30, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Mar 30, 2026
The upstream added a validate_safety_config function in stack.py, but this
branch removes the Safety/Shields API entirely, so the function is not needed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify mergify bot removed the needs-rebase label Mar 30, 2026
leseb and others added 16 commits March 31, 2026 15:22
Resolve merge conflicts in fastapi_router_registry.py and
llama_stack_api/__init__.py. Take upstream's auto-discovery approach for
router factories which replaces the hardcoded dict. Drop the
ViolationLevel export from __init__.py since the Safety API is removed
in this branch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Merge upstream/main into remove-safety-api branch. Resolved conflict in
streaming.py by taking upstream's ServiceTier wrapping while dropping
safety_identifier. Also removed safety_identifier references that upstream
added since the last merge, as this branch removes all safety-related code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Take upstream's updated test coverage score (44.1%) while merging
the remove-safety-api branch changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
The OpenAI coverage pre-commit hook regenerated the conformance
documentation to reflect the current integration test coverage score.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Resolve merge conflicts in the OpenAI conformance documentation. The
Moderations section added by upstream was removed since this branch
removes the Safety/Shields API. The Responses section from upstream was
kept as it is not safety-related and contains updated conformance data
without safety_identifier references.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
…fety code

Merge upstream/main into remove-safety-api branch, resolving conflicts in
docs/docs/api-openai/provider_matrix.md and streaming.py. Took upstream's
updated test numbers and ollama provider column, but removed safety_identifier
test rows. Removed the violation_detected check, _create_refusal_response
method, guardrails parameter, and safety-related docstring that were
auto-merged from upstream since this branch removes the Safety/Shields API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Remove guardrails parameter, ResponseGuardrailSpec/ResponseGuardrail types,
_create_refusal_response method, and safety-related integration tests that
were auto-merged from upstream. These additions are incompatible with this
branch which removes the Safety/Shields API entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Regenerate OpenAPI specifications to reflect the removal of
ResponseGuardrailSpec and guardrails field from the API models.
Fix linting in test_responses_errors.py for unused import.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
The merge with upstream/main re-introduced the Agents import in
stack.py which was removed as part of the safety API removal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Replace agents with responses in postgres-demo distribution config.
Remove shield_id test (shields removed), replace with vector_store_id.
Remove safety_api parameter from streaming test fixture.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
Tables now have rounded corners, subtle zebra striping, hover highlights,
purple-tinted headers, and cleaner borders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 1, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @leseb please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Apr 1, 2026
leseb and others added 2 commits April 1, 2026 22:36
Merge upstream/main into remove-safety-api branch. Resolved conflicts in
the OpenAPI spec files (llama-stack-spec.yaml, stainless-llama-stack-spec.yaml,
and client-sdks/stainless/openapi.yml) by keeping the new code samples from
upstream while removing the safety-related endpoints (/v1/moderations and
/v1/safety/run-shield) that upstream added. Also removed the moderations
code sample from scripts/openapi_generator/code_samples.py to stay consistent
with the safety API removal.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
The merge conflict resolution joined lines incorrectly in the spec files,
causing duplicate mapping keys. This commit applies the codegen fix to
properly separate the code sample endings from the next path entries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Sébastien Han <seb@redhat.com>
@mergify mergify bot removed the needs-rebase label Apr 1, 2026
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.

1 participant