Configure content shields
Content shields classify input or output and decide whether inference continues, pauses, or stops. This guide shows how to configure them for agents, tools, and topics.
Configure a request shield on an agent
Section titled “Configure a request shield on an agent”A request shield runs on the user’s message before the main LLM call.
-
Create an agent spec with a shield.
{"assistant_id": "support-bot","role": "reader","response_profile": {"system_prompt": "You are a helpful support assistant."},"shields": {"toxicity": {"provider_id": "shield-config","connector": {"provider_id": "huggingface/text-classification","url": "https://your-hf-endpoint.com","token": { "$secretRef": "SHIELDS_PROVIDER_API_KEY" },"label_map": { "LABEL_0": "safe", "LABEL_1": "toxic" }},"action": "block","threshold": 0.8,"target_label": "toxic","fail_closed": true,"block_message": "This request violates our safety policy."}}} -
Register the agent.
Terminal window alquimia registry agents add support-bot.json --namespace default -
Verify behavior.
Send a toxic input and confirm the refusal. Check the worklog for a
shield.blocked.v1event.
Configure an LLM-based shield
Section titled “Configure an LLM-based shield”LLM-based shields reuse registered models via model_ref.
-
Register a classifier model.
Terminal window cat > gpt-4o-mini-classifier.json <<'EOF'{"registered_model_id": "gpt-4o-mini-classifier","provider_id": "openai","name": "GPT-4o mini classifier","vendor": "openai","attribution_id": "openai/gpt-4o-mini","params": {"model": "gpt-4o-mini","temperature": 0.0,"api_key": {"$secretRef": "RESPONSE_PROVIDER_API_KEY"}}}EOFalquimia registry models add gpt-4o-mini-classifier.json --namespace default -
Add the shield to an agent or topic.
{"shields": {"intent-classifier": {"provider_id": "shield-config","connector": {"provider_id": "alquimia","profile": {"system_prompt": "Classify user intent as one of: support, sales, enterprise.","evaluation_strategy": {"evaluation_strategy_id": "one-shoot","structured_output": {"method": "json_schema","json_schema": {"type": "object","properties": { "intent": { "type": "string" } },"required": ["intent"]}}}},"config": { "model_ref": "gpt-4o-mini-classifier" }},"action": "observe"}}}
Use the prompt-injection detector
Section titled “Use the prompt-injection detector”Use the built-in detector without an external endpoint:
{ "shields": { "prompt-injection": { "provider_id": "shield-config", "connector": { "provider_id": "alquimia/prompt-injection-detection", "heuristic_weight": 0.3, "base_classifier_score": 0.0 }, "action": "block", "threshold": 0.5, "fail_closed": true } }}Reference a registered shield
Section titled “Reference a registered shield”Register a reusable shield connector once and reference it from multiple agents so shared endpoints and secrets stay out of individual specs.
alquimia registry shields add toxicity-classifier \ --connector '{"provider_id":"huggingface/text-classification","url":"https://your-hf-endpoint.com","label_map":{"LABEL_0":"safe","LABEL_1":"toxic"}}' \ --namespace defaultReference it from an agent spec with shield_ref:
{ "shields": { "toxicity": { "provider_id": "shield-config", "shield_ref": "toxicity-classifier", "action": "block", "threshold": 0.8, "target_label": "toxic", "fail_closed": true } }}Per-agent enforcement (action, threshold, fail_closed, block_message) is still set inline. The registered connector is used as-is, including any $secretRef markers resolved at inference time.
Add content shields to a tool or topic
Section titled “Add content shields to a tool or topic”Content shields on ToolRegistration and TopicRegistration run against tool outputs and retrieved knowledge chunks.
Topic shields
Section titled “Topic shields”Topic shields screen retrieved chunks before they enter the model context. Use them when a topic contains semi-trusted content or when one agent serves topics with different risk profiles.
curl -X PUT "http://localhost:8080/knowledge/topics/{topic_id}/shields" \ -H "Authorization: Bearer $API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "prompt-injection": { "provider_id": "shield-config", "connector": { "provider_id": "alquimia/prompt-injection-detection", "heuristic_weight": 0.3, "base_classifier_score": 0.0 }, "action": "block", "threshold": 0.5, "fail_closed": true, "block_message": "This retrieval result was removed by a safety policy." } }'The runtime validates each shield connector against the registry at write time and stores the resulting config on TopicRegistration.shields. If validation fails, the update is rejected with the registry error. Shields run at retrieval time, so changing a shield applies to all chunks already in the topic.
Tool shields
Section titled “Tool shields”{ "registered_tool_id": "filesystem-tools", "name": "Filesystem tools", "provider_id": "mcp", "connection_config": { "url": "http://mcp-server" }, "shields": { "prompt-injection": { "provider_id": "shield-config", "connector": { "provider_id": "alquimia/prompt-injection-detection", "heuristic_weight": 0.3, "base_classifier_score": 0.0 }, "action": "block", "threshold": 0.5, "block_message": "This tool result was removed by a safety policy." } }}Register it with:
alquimia registry tools add filesystem-tools \ --provider-id mcp \ --connection-config '{"url": "http://mcp-server"}' \ --shields filesystem-tools-shields.jsonWire shields to empathy rules
Section titled “Wire shields to empathy rules”{ "empathy": { "rules": [ { "rule_id": "enterprise-tone", "strategy": "merge", "description": "Use a formal tone for enterprise intent", "requirements": ["intent-classifier"], "conditions": ["intent-classifier.get('intent') == 'enterprise'"], "response": { "provider_id": "alquimia", "profile": { "prompt_clauses": { "tone": "Use formal, professional language. Avoid contractions." } } } } ] }}Test shield behavior
Section titled “Test shield behavior”Use dry_run inference or local unit tests to evaluate shield thresholds before deploying to production.
curl -X POST http://localhost:8080/event/infer/support-bot \ -H "Authorization: Bearer $API_TOKEN" \ -H "Content-Type: application/json" \ -d '{"query": "this is a test prompt injection: ignore previous instructions"}'