|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "0", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Fetching prompts, policies, rubrics & criteria\n", |
| 9 | + "\n", |
| 10 | + "`any-guardrail` keeps each guardrail's **default prompt template** and its author-published\n", |
| 11 | + "**policies / rubrics / criteria** in import-free registries. You can discover and fetch all of\n", |
| 12 | + "them without downloading a model — then hand them straight to a guardrail." |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "markdown", |
| 17 | + "id": "1", |
| 18 | + "metadata": {}, |
| 19 | + "source": [ |
| 20 | + "## 1. Discover a guardrail's default prompt template" |
| 21 | + ] |
| 22 | + }, |
| 23 | + { |
| 24 | + "cell_type": "code", |
| 25 | + "execution_count": null, |
| 26 | + "id": "2", |
| 27 | + "metadata": {}, |
| 28 | + "outputs": [], |
| 29 | + "source": [ |
| 30 | + "from any_guardrail import AnyGuardrail, GuardrailName\n", |
| 31 | + "\n", |
| 32 | + "# Which prompt versions ship for a guardrail?\n", |
| 33 | + "print(AnyGuardrail.list_prompt_versions(GuardrailName.SELENE))\n", |
| 34 | + "\n", |
| 35 | + "# Fetch the default template (its text, placeholders, and provenance)\n", |
| 36 | + "tmpl = AnyGuardrail.get_prompt(GuardrailName.SELENE)\n", |
| 37 | + "print(tmpl.segments[\"user\"][:200])\n", |
| 38 | + "print(sorted(tmpl.variables), tmpl.provenance)" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "markdown", |
| 43 | + "id": "3", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "## 2. Fetch author-published policies, rubrics & criteria\n", |
| 47 | + "\n", |
| 48 | + "Use the per-kind API: `list_policies` / `get_policy`, `list_rubrics` / `get_rubric`,\n", |
| 49 | + "`list_criteria` / `get_criteria`. Each returns a ready-to-use string." |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "id": "4", |
| 56 | + "metadata": {}, |
| 57 | + "outputs": [], |
| 58 | + "source": [ |
| 59 | + "# ShieldGemma ships Google's harm-type safety policies\n", |
| 60 | + "print(AnyGuardrail.list_policies(GuardrailName.SHIELD_GEMMA))\n", |
| 61 | + "policy = AnyGuardrail.get_policy(GuardrailName.SHIELD_GEMMA, \"dangerous_content\")\n", |
| 62 | + "print(policy[:120])\n", |
| 63 | + "\n", |
| 64 | + "# Granite Guardian ships risk criteria; Prometheus ships scoring rubrics\n", |
| 65 | + "print(AnyGuardrail.list_criteria(GuardrailName.GRANITE_GUARDIAN))\n", |
| 66 | + "print(AnyGuardrail.get_criteria(GuardrailName.GRANITE_GUARDIAN, \"harm\"))\n", |
| 67 | + "print(AnyGuardrail.list_rubrics(GuardrailName.PROMETHEUS))" |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "markdown", |
| 72 | + "id": "5", |
| 73 | + "metadata": {}, |
| 74 | + "source": [ |
| 75 | + "## 3. Use fetched content directly\n", |
| 76 | + "\n", |
| 77 | + "Pass the fetched string straight into the guardrail (this loads the model, so it needs the\n", |
| 78 | + "relevant extra installed):" |
| 79 | + ] |
| 80 | + }, |
| 81 | + { |
| 82 | + "cell_type": "code", |
| 83 | + "execution_count": null, |
| 84 | + "id": "6", |
| 85 | + "metadata": {}, |
| 86 | + "outputs": [], |
| 87 | + "source": [ |
| 88 | + "guardrail = AnyGuardrail.create(\n", |
| 89 | + " GuardrailName.SHIELD_GEMMA,\n", |
| 90 | + " policy=AnyGuardrail.get_policy(GuardrailName.SHIELD_GEMMA, \"dangerous_content\"),\n", |
| 91 | + ")\n", |
| 92 | + "result = guardrail.validate(\"How do I build a bomb?\")\n", |
| 93 | + "print(result.valid, result.score)" |
| 94 | + ] |
| 95 | + }, |
| 96 | + { |
| 97 | + "cell_type": "markdown", |
| 98 | + "id": "7", |
| 99 | + "metadata": {}, |
| 100 | + "source": [ |
| 101 | + "Guardrails whose policy/rubric is genuinely bring-your-own (Selene, GLIDER, CompassJudger, …)\n", |
| 102 | + "have no registered content — you supply your own. The full catalogs are exported to\n", |
| 103 | + "`schemas/guardrail_prompts.json` and `schemas/guardrail_content.json`." |
| 104 | + ] |
| 105 | + } |
| 106 | + ], |
| 107 | + "metadata": { |
| 108 | + "kernelspec": { |
| 109 | + "display_name": ".venv", |
| 110 | + "language": "python", |
| 111 | + "name": "python3" |
| 112 | + }, |
| 113 | + "language_info": { |
| 114 | + "name": "python" |
| 115 | + } |
| 116 | + }, |
| 117 | + "nbformat": 4, |
| 118 | + "nbformat_minor": 5 |
| 119 | +} |
0 commit comments