Quickstart
Point your OpenAI-compatible SDK at the ValGuard integrity layer and set X-VG-Agent to your agent slug (or X-VG-Flow for playbooks). Create agents and API keys in the dashboard.
Quick start
- Create or pick an agent in Dashboard → Agents (use Create agent, then choose a preset or blank agent).
- Create an API key in the dashboard and copy the value.
- Set environment variables for the API URL, API key, and the agent slug you want to use.
- Send your first request to
/v1/chat/completionswith a simplemodelandmessagespayload.
Set environment variables
export VG_PROXY="https://api.valguard.ai" export VG_API_KEY="vg_live_YOUR_KEY" # from https://valguard.ai/dashboard export VG_AGENT="default" # agent slug
SDKs at a glance
The public SDK surface is available in the monorepo packages for Python, Node.js, Go, and C#; each one exposes a thin client that forwards headers and parses ValGuard validation metadata.
SDK packages
Source lives on GitHub at github.com/valguard-ai/sdk-python, sdk-node, sdk-go, sdk-csharp or copy the snippets below. npm scope is @valguard.
What the SDKs cover
Injects the API key and agent slug automatically.
Parses X-VG-* headers and soft-fail payloads.
Supports provider keys and retrieved-source metadata where enabled.
Works with the official OpenAI SDK clients for Python and Node.js.
Python
pip install valguard-sdk (import stays valguard). Do not run pip install valguard: that name on PyPI is an unrelated project (jhmanton/valguard). This client publishes as valguard-sdk. Git install: pip install "git+https://github.com/valguard-ai/sdk-python.git". Examples use groq/openai/gpt-oss-20b; any provider/model works, for example groq/llama-3.3-70b-versatile.
from openai import OpenAI
from valguard import ValGuardClient
vg = ValGuardClient.from_env()
client = OpenAI(**vg.openai_client_kwargs())
raw = client.with_raw_response.chat.completions.create(
model="groq/openai/gpt-oss-20b",
messages=[{"role": "user", "content": "Return JSON with name Ada Lovelace and email ada@example.com"}],
)
print(vg.parse_response_headers(dict(raw.http_response.headers)))
print(raw.parse())Node.js
npm install @valguard/sdk-node (local: npm install ./packages/sdk-node). The unscoped npm package valguard is a placeholder, not this client.
import OpenAI from "openai";
import { ValGuard } from "@valguard/sdk-node";
const vg = ValGuard.fromEnv();
const client = new OpenAI(vg.openaiOptions());
const raw = await client.chat.completions.create({
model: "groq/openai/gpt-oss-20b",
messages: [{ role: "user", content: "Return JSON with name Ada Lovelace and email ada@example.com" }],
}).withResponse();
console.log(vg.parseResponseHeaders(raw.response.headers));
console.log(raw.data);Go
go get github.com/valguard-ai/sdk-go
package main
import (
"context"
"fmt"
"log"
"github.com/valguard-ai/sdk-go/valguard"
)
func main() {
client, err := valguard.FromEnv()
if err != nil {
log.Fatal(err)
}
result, err := client.ChatCompletions(context.Background(), valguard.ChatRequest{
Model: "groq/openai/gpt-oss-20b",
Messages: []valguard.Message{
{Role: "user", Content: "Return JSON with name Ada Lovelace and email ada@example.com"},
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(result.Validation)
}C#
dotnet add package ValGuard.Sdk
using ValGuard.Sdk;
var vg = ValGuardClient.FromEnv();
var result = await vg.ChatCompletionsAsync(new ChatRequest(
Model: "groq/openai/gpt-oss-20b",
Messages: [new ChatMessage("user", "Return JSON with name Ada Lovelace and email ada@example.com")]));
Console.WriteLine(result.Validation);curl
curl -s "$VG_PROXY/v1/chat/completions" \
-H "Authorization: Bearer $VG_API_KEY" \
-H "X-VG-Agent: $VG_AGENT" \
-H "Content-Type: application/json" \
-d '{
"model":"groq/openai/gpt-oss-20b",
"messages":[
{"role":"system","content":"You are a safe, validated assistant."},
{"role":"user","content":"Return JSON with name Ada Lovelace and email ada@example.com"}
]
}'With real upstream, add -H "X-Provider-Key: sk-…" or configure provider vault (Developer+) — including custom base URLs for self-hosted models on Growth+ (vLLM, Ollama, LiteLLM, private Azure, on-prem endpoints).
Zapier / Make / n8n
- HTTP POST to
https://api.valguard.ai/v1/chat/completions - Headers:
Authorization: Bearer …,X-VG-Agent: default,Content-Type: application/json - Body: OpenAI chat completions JSON (model, messages)
What is X-VG-Agent?
The agent slug selects which validator ruleset runs on the response. Default is default. Create agents and edit validators in the dashboard — each agent can have different providers, reask limits, and on_fail policies (block, reask, warn, pass).
RAG sources (Phase B)
For RAG agents (rag_citation_validator_agent, rag_source_matching_agent), pass retrieved chunks via X-VG-Sources. Validators check citations and grounding deterministically — no LLM-as-judge.
curl -s "$VG_PROXY/v1/chat/completions" \
-H "Authorization: Bearer $VG_API_KEY" \
-H "X-VG-Agent: rag_citation_validator_agent" \
-H 'X-VG-Sources: [{"id":"1","text":"Acme revenue was 10M in 2024."}]' \
-H "Content-Type: application/json" \
-d '{
"model":"groq/openai/gpt-oss-20b",
"messages":[{"role":"user","content":"Summarize Acme revenue with citation [1]"}]
}'Model routing
Use provider/model — e.g. anthropic/claude-sonnet-4-20250514, xai/grok-4, google/gemini-flash-latest. For models you host yourself or on a private endpoint, vault slugs become the prefix (for example my-cluster/Meta-Llama-3-8B-Instruct). See providers.
Response headers
- X-VG-Validation-Status: pass | warn | block | shadow | stream_passthrough | fail
- X-VG-Shadow-Mode: true (when agent shadow mode is on)
- X-VG-Latency-ms: numeric
- X-Vg-Upstream-Retries: integer (0+ on agent and playbook completions; omitted on auth/early rejects)
- X-VG-Request-Id: canonical id (client RFC 4122 UUID adopted, else minted v4)
- X-Request-Id: matches X-VG-Request-Id on proxied responses
- X-VG-Span-Id: 16 lowercase hex (this hop; omitted on nginx-only JSON errors)
- X-Vg-Max-Tokens-Adjusted: set when a length-retry raised max_tokens (for example 48->256)
- X-VG-Healed: true only when the final response passed because of repair. A blocked repair is X-VG-Repair-Attempted and does not set X-VG-Healed
- X-VG-Healed-Rules: comma-separated repair rule ids
- X-VG-Healed-Event-Count: repair event count
- X-VG-Healed-Trace: comma-separated rule@field entries
- X-VG-Cache: cache_hit
- X-Trace-Id, X-VG-Span-Id, X-VG-Parent-Span-Id, X-VG-Agent-Id
Shadow mode
Enable shadow mode on an agent to log validation failures without blocking or re-asking. The upstream response always passes through — ideal for measuring failure rates before production enforce mode.
Dashboard requests show status shadow when a block/reask rule would have fired. Response headers include X-VG-Shadow-Mode: true, X-VG-Validation-Status: shadow, and X-VG-Warnings with would_block plus the rule name and id. Blocking responses name the same rule in the error body.
While shadow mode is on, validation failure response settings are disabled — callers are never blocked by validators. Tune validators, then disable shadow mode and switch critical rules to on_fail: block.
Shadow mode does not bypass the monthly agent budget. A hard spend cap is a billing control and still returns HTTP 402 when recorded spend has reached the cap, including while shadow mode is on.
Validation webhooks
ValGuard sends an asynchronous HTTPS POST when a completion is blocked or when shadow mode records a would-block violation. Delivery is non-blocking on the layer hot path (5 second timeout per attempt).
- validation.block — a blocking validator failed and the response was not passed through (unless shadow mode is on).
- validation.shadow — shadow mode logged a failure that would have blocked or re-asked in enforce mode.
Configure the default URL under Organization settings → Validation webhooks. Per agent, set Validation webhook override to replace the org URL; leave it empty to inherit the organization webhook.
JSON body (failures are redacted according to the agent log level):
{
"event": "validation.block",
"request_id": "550e8400-e29b-41d4-a716-446655440000",
"agent": { "slug": "default", "name": "Default" },
"failures": [
{ "validator": "pii_email", "message": "…" }
]
}The receiver should return HTTP 2xx. Non-success statuses and network errors are recorded in webhook delivery logs. Use HTTPS endpoints in production.
Monthly agent budget
Monthly budget (USD) is a hard spend cap per agent. The layer estimates cost from token usage and blocks the next request only after recorded spend for that agent has reached the cap. A cap with zero recorded spend does not block. The check runs before shadow mode and is not suppressed by it.
0disables the cap.- HTTP 402
agent_budget_exceededuses error typebilling_errorand includesbudget_usd,spend_usd, andspend_micro_usd. The response also setsX-VG-Request-Id. - Organization plan quotas and monthly request caps still apply separately — see billing and usage in the dashboard.
Log level & privacy
Each agent has a log level (metadata default, hashed, or full). Before validation results are queued for storage, ValGuard.ai masks emails, tax IDs (NIP/PESEL/SSN), IBAN, card numbers, and sensitive JSON field values.
metadata— recommended for production; stores rule outcomes without raw prompt/response text.hashed— strictest; minimal retained detail.full— debug only; use with consent and short retention.
payload_retention_days controls how long stored detail payloads are kept; the retention job clears those fields afterward. Webhook failure payloads follow the same redaction rules.
Validation failure response
When a blocking validator fails (and shadow mode is off), choose how the layer responds:
- HTTP error — returns
403by default as HTTP 403 (or 400, 409, 422 when the agent sets that status) witherror.type,reason, anddetails. - Soft envelope — HTTP 200 with
valid: falseplus avalidationobject for clients that cannot handle error status codes.
See the error reference for header and body shapes.
Streaming (stream: true)
- Passthrough SSE (warn/pass only) — If no enabled validator uses
on_fail: blockoron_fail: reask, chunks are forwarded immediately while assistant text is collected for post-stream validation, logging, and shadow mode. - Buffered validation + synthesized SSE — If any enabled rule can block or reask, the layer reads the upstream stream internally and validates the assembled assistant reply. A passing reply is replayed as OpenAI-compatible SSE. A block, reask failure, or upstream error before the stream starts is ordinary JSON with an HTTP status (for example 403), not an SSE event. Blocked responses on stream:true return 403 application/json, not SSE. Mock upstream mode uses this buffered path.
Custom endpoints (Growth+)
Register private or on-premises models under Provider vault → Custom endpoint: pick an adapter (openai_compat, Anthropic Messages, or Gemini), base URL, optional Azure deployment/version, headers, and timeout — typical stacks include vLLM, Ollama, LiteLLM, private Azure, or approved on-prem endpoints. Route with your-slug/model-name. See Supported providers for the full rundown; shadow mode and validation behavior match built-in providers.
Privacy (GDPR / RODO)
Each agent has a log level (metadata default, hashed, or full). Before validation results are queued for storage, ValGuard.ai masks emails, tax IDs (NIP/PESEL/SSN), IBAN, card numbers, and sensitive JSON field values.
metadata— recommended for production; stores rule outcomes without raw prompt/response text.hashed— strictest; minimal retained detail.full— debug only; use with consent and short retention.
payload_retention_days controls how long stored detail payloads are kept; the retention job clears those fields afterward. Webhook failure payloads follow the same redaction rules.
Organization owners can request GDPR erasure in dashboard settings — the org is deactivated immediately and hard-deleted after 30 days (make process-erasure). Run make purge-retention for the daily payload retention job.
Errors
- validation_block — default
403witherror.type,reason,details. Per agent you can choose a hard 4xx (400, 403, 409, 422) or HTTP 200 withvalid: falseplus avalidationobject (Agent settings). - 429 rate_limited — backoff (auth failures per IP, or org throughput limits)
- 429 monthly_cap_exceeded — upgrade plan or enable overage billing on a paid subscription
Next steps
- Sign up and generate an API key
- Apply a template (e.g. lead capture, invoice extraction) to your agent
- Run in shadow mode while tuning rules — failures are logged but responses pass through
- Switch critical validators to block before production traffic