Skip to main content

QWED protocol specification v1.0

Status: Draft
Version: 1.0.0
Date: 2025-12-20
Authors: QWED-AI Team

Table of contents

  1. Introduction
  2. Protocol philosophy
  3. Architecture overview
  4. Verification types
  5. Request format
  6. Response format
  7. QWED-Logic DSL
  8. Error codes
  9. Versioning
  10. Security considerations
  11. Conformance

1. Introduction

1.1 Purpose

The QWED Protocol defines a standard interface for deterministic verification of AI-generated content. It enables any system to verify the correctness of claims, calculations, logic, code, and other outputs from Large Language Models (LLMs).

1.2 Scope

This specification covers:
  • Verification request and response formats
  • Supported verification types (engines)
  • The QWED-Logic Domain Specific Language (DSL)
  • Error handling and status codes
  • Protocol versioning

1.3 Terminology

1.4 Notational conventions

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

2. Protocol philosophy

2.1 Core principle: LLM as untrusted translator

QWED treats LLMs as untrusted translators. The LLM’s role is to convert natural language into a symbolic representation that can be verified by deterministic engines. The verification step provides the guarantee.

2.2 Design goals

2.3 Trust model


3. Architecture overview

3.1 Protocol layers

3.2 Request flow

3.3 Transport

  • Primary: HTTP/1.1 or HTTP/2
  • Content-Type: application/json
  • Encoding: UTF-8
  • Authentication: Via X-API-Key header or Bearer token (implementation-defined)

4. Verification types

4.1 Engine registry

4.2 Engine capabilities

Each engine MUST declare its capabilities:

5. Request format

5.1 Base request schema

All verification requests MUST conform to this base schema:

5.2 Engine-specific request schemas

5.2.1 Math verification

5.2.2 Logic verification

5.2.3 Code verification

5.2.4 Fact verification

5.2.5 SQL verification

5.3 Batch request


6. Response format

6.1 Base response schema

6.2 Status codes

6.3 Example responses

6.3.1 Successful math verification

6.3.2 Failed verification

6.3.3 Logic verification with model

6.3.4 Security block

6.4 Batch response


7. QWED-Logic DSL

7.1 Overview

QWED-Logic is an S-expression based Domain Specific Language for expressing logical constraints. It is designed to be:
  • Easy for LLMs to generate
  • Safe to parse (no eval)
  • Expressive for common logic patterns

7.2 Grammar (EBNF)

7.3 Operator reference

7.3.1 Logic operators

7.3.2 Comparison operators

7.3.3 Arithmetic operators

7.3.4 Quantifiers

7.4 Examples

Simple constraint

Invoice validation

Business rule

7.5 Variable declaration

Variables are automatically inferred from usage. The default type is Real. Explicit type declarations:

7.6 Security

QWED-Logic DSL is designed to be safe by construction:
  • No code execution (unlike eval)
  • Whitelist-based operator validation
  • Bounded recursion depth
  • Input length limits

8. Error codes

8.1 Error code format

8.2 Error categories

8.3 Error code registry

8.4 Error response format


9. Versioning

9.1 Semantic versioning

The QWED Protocol follows Semantic Versioning 2.0.0:

9.2 Version negotiation

Clients SHOULD include the protocol version in requests:
Servers MUST include the protocol version in responses:

9.3 Compatibility


10. Security considerations

10.1 Input validation

Implementations MUST:
  • Validate all input against JSON Schema
  • Enforce maximum query length (RECOMMENDED: 100KB)
  • Sanitize inputs before engine processing

10.2 Prompt injection defense

Implementations SHOULD:
  • Scan for known injection patterns
  • Block requests containing manipulation attempts
  • Log security events

10.3 Rate limiting

Implementations SHOULD implement:
  • Per-client rate limiting
  • Global rate limiting
  • Burst allowance

10.4 Audit logging

Implementations SHOULD log:
  • All verification requests (with timestamps)
  • Security violations
  • Errors

10.5 Transport security

  • HTTPS MUST be used in production
  • TLS 1.2+ REQUIRED

11. Conformance

11.1 Conformance levels

11.2 Conformance testing

A conformance test suite is available at:

11.3 Implementation registry

Compliant implementations MAY be registered at:

Appendix A: JSON schemas

Full JSON Schema files are available at:
  • Request: https://qwedai.com/schemas/request/v1.json
  • Response: https://qwedai.com/schemas/response/v1.json

Appendix B: Reference implementation

The reference implementation is available at:
  • GitHub: https://github.com/QWED-AI/qwed-verification
  • Docker: docker pull qwed/qwed-node:latest

Appendix C: Change log

v1.0.0 (2025-12-20)

  • Initial specification release
  • 8 verification engines defined
  • QWED-Logic DSL v1.0

© 2025 QWED-AI. This specification is released under Apache 2.0 License.