Skip to main content
The Python SDK provides schema validation with detailed error reporting and warnings for Beltic credentials.

Basic Validation

DeveloperCredential

from beltic import validate_developer_credential, ValidationError

# Validate a credential
result = validate_developer_credential(credential_data)

if result.ok:
    credential = result.value
    print(f"Valid! Developer: {credential['legalName']}")
    
    # Check for warnings (e.g., stale data)
    if result.warnings:
        for warning in result.warnings:
            print(f"Warning: {warning.message}")
else:
    # Handle validation errors
    for error in result.errors:
        print(f"Error at {error.path}: {error.message}")

AgentCredential

from beltic import validate_agent_credential

result = validate_agent_credential(agent_data)

if result.ok:
    agent = result.value
    print(f"Valid! Agent: {agent['agentName']}")
    print(f"Safety Score: {agent['harmfulContentRefusalScore']}")

Validation Result Types

from beltic import ValidationResult

# Result is a union type:
# - Success: { ok: True, value: T, warnings: list[ValidationWarning] }
# - Failure: { ok: False, errors: list[ValidationErrorDetail] }

result = validate_developer_credential(data)

if result.ok:
    # Type narrowing: result.value is the validated credential
    credential = result.value
    warnings = result.warnings
else:
    # Type narrowing: result.errors contains validation errors
    errors = result.errors

Error Handling

Using ValidationError

from beltic import ValidationError, validate_developer_credential

try:
    result = validate_developer_credential(data)
    if not result.ok:
        raise ValidationError(result.errors)
except ValidationError as e:
    # Pretty-printed error message
    print(e.format())
    
    # Access individual issues
    for issue in e.issues:
        print(f"  Path: {issue.path}")
        print(f"  Code: {issue.code}")
        print(f"  Message: {issue.message}")
    
    # Group errors by path
    by_path = e.by_path()
    for path, errors in by_path.items():
        print(f"{path}: {len(errors)} error(s)")

Error Detail Structure

class ValidationErrorDetail:
    path: str           # JSON path (e.g., "/legalName")
    code: str           # Error code (e.g., "RV-D001")
    message: str        # Human-readable message
    severity: str       # "error" or "warning"
    suggestion: str     # Optional fix suggestion

Type Guards

from beltic import is_developer_credential, is_agent_credential

def process_credential(credential: dict):
    if is_developer_credential(credential):
        # Type checker knows this is a DeveloperCredential
        print(f"Developer: {credential['legalName']}")
        print(f"KYB Tier: {credential['kybTier']}")
    
    elif is_agent_credential(credential):
        # Type checker knows this is an AgentCredential
        print(f"Agent: {credential['agentName']}")
        print(f"Version: {credential['agentVersion']}")

Common Validation Errors

Required Field Missing

# Input missing required field
data = {"entityType": "corporation"}  # Missing legalName

result = validate_developer_credential(data)
# Error: /legalName - Required property 'legalName' is missing

Invalid Enum Value

data = {
    "legalName": "Acme Corp",
    "entityType": "invalid_type"  # Not a valid enum value
}

result = validate_developer_credential(data)
# Error: /entityType - Value must be one of: corporation, individual, ...

Conditional Validation

# If taxIdExists is true, taxIdVerified is required
data = {
    "legalName": "Acme Corp",
    "taxIdExists": True,
    # Missing taxIdVerified!
}

result = validate_developer_credential(data)
# Error: /taxIdVerified - Required when taxIdExists is true

Date Validation

data = {
    "issuanceDate": "2025-01-01T00:00:00Z",
    "expirationDate": "2024-01-01T00:00:00Z",  # Before issuance!
}

result = validate_developer_credential(data)
# Error: RV-D001 - issuanceDate must be before expirationDate

Freshness Warnings

The SDK warns about stale verification data:
result = validate_developer_credential(data)

if result.ok and result.warnings:
    for warning in result.warnings:
        if warning.code == "RV-F001":
            print("Sanctions screening is stale (>90 days)")
        elif warning.code == "RV-F002":
            print("PEP assessment is stale (>180 days)")
CodeWarning
RV-F001Sanctions screening is stale (>90 days)
RV-F002PEP assessment is stale (>180 days)
RV-F003Adverse media assessment is stale (>180 days)
RV-F004Tax verification is stale (>730 days)
RV-F005Credential expired

Batch Validation

from beltic import validate_agent_credential

credentials = load_credentials_from_file("agents.json")

valid = []
invalid = []

for cred in credentials:
    result = validate_agent_credential(cred)
    if result.ok:
        valid.append(result.value)
    else:
        invalid.append({
            "credential": cred,
            "errors": result.errors
        })

print(f"Valid: {len(valid)}, Invalid: {len(invalid)}")

Next Steps

Signing & Verification

Sign validated credentials as JWS tokens

Trust Chains

Verify agent-developer trust chains