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 proxy 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
Install from the monorepo (packages/sdk-python, packages/sdk-node, packages/sdk-go, packages/sdk-csharp) or copy the snippets below.
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 (local: pip install -e ./packages/sdk-python)
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="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "Say hi"}],
)
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)
import OpenAI from "openai";
import { ValGuard } from "@valguard/sdk-node";
const vg = ValGuard.fromEnv();
const client = new OpenAI(vg.openaiOptions());
const raw = await client.withRawResponse.chat.completions.create({
model: "openai/gpt-4o-mini",
messages: [{ role: "user", content: "Say hi" }],
});
console.log(vg.parseResponseHeaders(raw.response.headers));
console.log(raw.parse());Go
go get github.com/valguard/valguard/packages/sdk-go
package main
import (
"context"
"fmt"
"log"
"github.com/valguard/valguard/packages/sdk-go/valguard"
)
func main() {
client, err := valguard.FromEnv()
if err != nil {
log.Fatal(err)
}
result, err := client.ChatCompletions(context.Background(), valguard.ChatRequest{
Model: "openai/gpt-4o-mini",
Messages: []valguard.Message{
{Role: "user", Content: "Say hi"},
},
})
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: "openai/gpt-4o-mini",
Messages: [new ChatMessage("user", "Say hi")]));
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":"openai/gpt-4o-mini",
"messages":[
{"role":"system","content":"You are a safe, validated assistant."},
{"role":"user","content":"Say hi"}
]
}'With real upstream, add -H "X-Provider-Key: sk-…" or configure provider vault (Growth+) — including custom base URLs for self-hosted models (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":"openai/gpt-4o-mini",
"messages":[{"role":"user","content":"Summarize Acme revenue with citation [1]"}]
}'Model routing
Use provider/model — e.g. anthropic/claude-3-5-sonnet-20241022, openrouter/anthropic/claude-3.5-sonnet, perplexity/sonar-pro. 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
- X-VG-Shadow-Mode: true (when agent shadow mode is on)
- X-VG-Latency-ms: numeric
- X-VG-Request-Id: uuid
- X-Request-Id: uuid (same 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 and X-VG-Validation-Status: shadow.
While shadow mode is on, validation failure response settings are disabled — callers are never blocked. Tune validators, then disable shadow mode and switch critical rules to on_fail: block.
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 soft spend cap per agent. The layer estimates cost from token usage and blocks new requests when monthly spend for that agent exceeds the budget.
0disables the cap.- Organization plan quotas and monthly validation 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 (or 400, 409, 422 per agent) 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, validates the assembled assistant reply, then replays OpenAI-compatible SSE with the final text (or a block/reask envelope). 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_limit_exceeded — backoff; check plan quotas
- 429 monthly_cap_exceeded — upgrade plan or enable overage billing
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