docs: migrate Guardian documentation from deprecated GuardianCheck to Intrinsics API#935
Draft
planetf1 wants to merge 6 commits intogenerative-computing:mainfrom
Draft
docs: migrate Guardian documentation from deprecated GuardianCheck to Intrinsics API#935planetf1 wants to merge 6 commits intogenerative-computing:mainfrom
planetf1 wants to merge 6 commits intogenerative-computing:mainfrom
Conversation
684ba01 to
3e0d4dc
Compare
…anCheck to Intrinsics API Migrates docs, examples, and cross-links from the deprecated GuardianCheck/GuardianRisk API to the current Guardian Intrinsics API (guardian_check(), policy_guardrails(), factuality_detection(), factuality_correction()). - New how-to/safety-guardrails.md: full reference for all four Intrinsic functions, CRITERIA_BANK keys, and the target_role="user" input-gating pattern - Tutorial 04 steps 4–7 rewritten to use Intrinsics; prerequisites updated - Glossary: 5 new entries; GuardianCheck/GuardianRisk entries marked deprecated - Deprecation banners added to security-and-taint-tracking.md and three example files - docs.json: safety-guardrails added to nav; temporary redirect removed - Cross-links updated in intrinsics.md, index.mdx, build-a-rag-pipeline.md, use-context-and-sessions.md, common-errors.md, architecture-vs-agents.md, plugins.mdx Partially addresses generative-computing#639, generative-computing#802. Assisted-by: Claude Code
- Fix stale `grounding_context` tip in tutorial step 6 — was referencing
a parameter removed from the code example (3/3 reviewer consensus)
- Add deprecation notice to docs/examples/safety/README.md to match the
deprecation docstrings already added to the three .py files
- Resolve duplicate `intrinsics/` entries in examples/index.md — the Safety
section row covers Guardian functions; the Performance row gains a
"(Non-Guardian)" qualifier with a cross-reference
- Tutorial step 7: add user message to eval_ctx for consistency with all
other guardian_check() examples
- safety-guardrails.md: add migration callout after custom criteria section
noting that not all deprecated GuardianRisk values have CRITERIA_BANK keys
- safety-guardrails.md: add note clarifying counterintuitive factuality_detection()
return semantics ("yes" = incorrect, "no" = correct)
- troubleshooting/common-errors.md: add factuality_correction() to the
Guardian Intrinsics list (was omitted alongside the other three functions)
- security-and-taint-tracking.md: update frontmatter description to signal
deprecation in search results and link previews
- security-and-taint-tracking.md: fix imprecise "no separate Guardian model
pull" claim — intrinsics still download a model, just a different one
Assisted-by: Claude Code
…telemetry gap Guardian Intrinsics are not Requirement subclasses and emit no mellea.requirement.checks/failures metrics. Users migrating from GuardianCheck would otherwise lose those counters silently. Also fix "Determine is" → "Determine if" typo in factuality_detection docstring. Assisted-by: Claude Code
3e0d4dc to
51b4160
Compare
…view - plugins.mdx: fix broken OTel link (evaluation-and-observability/... → observability/tracing) - build-a-rag-pipeline: correct # Returns comment (None → float 0.0–1.0) - safety-guardrails: add context-attachment pattern note to factuality section explaining why .add(Document) differs from documents= kwarg; add warning about -> float annotation mismatch (tracked as generative-computing#934) - glossary: fix past-tense "validated" → "validates" in GuardianCheck entry - deprecated safety examples: drop # pytest: markers so they are no longer collected by CI (GuardianCheck removal won't break CI in future) Assisted-by: Claude Code
guardian.py, guardian_huggingface.py, and repair_with_guardian.py are fully superseded by docs/examples/intrinsics/guardian_core.py, factuality_detection.py, factuality_correction.py, and policy_guardrails.py. One migration gap documented in safety/README.md: the old repair_with_guardian.py pattern (GuardianCheck as a Requirement inside RepairTemplateStrategy, with _reason fed back as repair guidance) has no direct equivalent in the Intrinsics API — Guardian Intrinsics return float scores, not Requirement results, and do not expose a chain-of-thought reason string. Assisted-by: Claude Code
- Fix -> float annotations on factuality_detection/factuality_correction (resolves generative-computing#934; closes the stale type-lie now that file was touched) - Fix troubleshooting groundedness bullet: wrong document placement (was "user message", correct is assistant Message with documents=[...]) - SafeChatSession: accept guardian_backend as constructor arg instead of instantiating LocalHFBackend internally (matches "create once, reuse" guidance) - Name SEXUAL_CONTENT migration gap explicitly in safety-guardrails.md callout - Move mellea[hf] prerequisite to RAG guide prerequisites block; drop inline note - Remove -> float type annotation caveat from safety-guardrails.md (fixed in source) - Remove "sexual_content" from tutorial CRITERIA_BANK key lists (not a real key) Assisted-by: Claude Code Signed-off-by: Nigel Jones <jonesn@uk.ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Guardian Documentation Migration
Status
Paused as of 2026-05-01. This PR depends on active intrinsics work that is still in flux:
nathan/intrinsic_examples_version_bump) — bumps all intrinsic examples fromgranite-4.0-microtogranite-4.1-3b. All code examples in this PR use the old model ID and will need a sweep-and-replace once feat: update granite library examples to use Granite 4.1 3B adapters. #981 merges.jal/fix-intrinsic-issues) — fixes failures introduced by recent intrinsic changes (nightlies currently broken per Failing nightlies in2026-04-30-0f95f84#985).jal/add-test-for-intrinsic-name) — adds tests for new intrinsic field name behaviour.Plan: wait for #981, #986, and #988 to merge and stabilise, then re-review this PR, update model IDs throughout, and verify examples against the new adapter versions before marking ready.
Type of PR
Description
Migrates Guardian documentation from the deprecated
GuardianCheck/GuardianRiskAPI (emitsDeprecationWarningsince v0.4) to the current Guardian Intrinsics API (guardian_check(),policy_guardrails(),factuality_detection(),factuality_correction()).Key changes:
/how-to/safety-guardrailspage — full reference for all four Intrinsic functions,CRITERIA_BANKkeys, and thetarget_role="user"input-gating patternbuild-a-rag-pipeline.mdstep 5 and "Putting it together" rewritten to useguardian_check(criteria="groundedness")withDocument(text=..., doc_id=...)attached to the assistant message (aligned with fix: add guardian intrinsic document #966)docs/examples/safety/example files deleted —guardian.py,guardian_huggingface.py, andrepair_with_guardian.pyremoved (see below)security-and-taint-tracking.mdguardian_check,CRITERIA_BANK,policy_guardrails,factuality_detection,factuality_correction);GuardianCheck/GuardianRiskentries marked deprecateddocs.json:how-to/safety-guardrailsadded to nav; redirect from that path tosecurity-and-taint-trackingremovedexamples/index.md:intrinsics/category description updated to clarify Guardian functions are documented separatelyadvanced/intrinsics.mdindex.mdxupdated to reference Intrinsicsuse-context-and-sessions.mdrewritten (SafeChatSessionnow acceptsguardian_backendas a constructor arg)concepts/architecture-vs-agents.md,concepts/plugins.mdx, andguide/CONTRIBUTING.mdlinks updatedobservability/metrics.md: note added that Guardian Intrinsics do not emitmellea.requirementmetrics (migration footgun)"Determine is"→"Determine if"infactuality_detectiondocstring-> floatreturn annotations onfactuality_detection/factuality_correction(they returnstr; closes fix(core): wrong return type annotations on factuality_detection and factuality_correction #934)"sexual_content"from tutorial CRITERIA_BANK key list (not a real key;GuardianRisk.SEXUAL_CONTENThas no equivalent inCRITERIA_BANK)Note on tutorial 04: Steps 4–7 of
04-making-agents-reliable.mdwere independently migrated to Guardian Intrinsics upstream before this PR was rebased; those upstream changes were taken as-is.Deletion of
docs/examples/safety/examples — reviewer input requestedguardian.py,guardian_huggingface.py, andrepair_with_guardian.pyhave been deleted rather than retained with deprecation markers. Rationale:guardian.pyandguardian_huggingface.pyare fully superseded bydocs/examples/intrinsics/guardian_core.py, which covers all the same criteria (harm, jailbreak, social_bias, groundedness, function_call, custom criteria) against the same HuggingFace backend. Keeping them would mean CI eventually breaking whenGuardianCheckis removed, with no benefit.repair_with_guardian.pydemonstratedGuardianCheckas aRequirementinsideRepairTemplateStrategy, where Guardian's chain-of-thought_reasonstring was fed back as repair guidance. This pattern has no direct equivalent in the Guardian Intrinsics API: Intrinsics return afloatscore and do not expose a reasoning string, so they cannot be passed tom.validate()or wired intoRepairTemplateStrategydirectly. Asafety/README.mdis retained to document this gap explicitly.If you believe
repair_with_guardian.pyshould be kept (or that theRepairTemplateStrategygap warrants a separate issue), please comment — the example can be restored.Testing
Attribution