Metadata-Version: 2.5
Name: urml-validator
Version: 0.5.4
Summary: Static verification engine for URML — Universal Robot Language
Project-URL: Homepage, https://github.com/urml-dev/URML
Project-URL: Repository, https://github.com/urml-dev/URML
Project-URL: Issues, https://github.com/urml-dev/URML/issues
Author: URML Maintainers
License: BUSL-1.1
License-File: LICENSE
Keywords: robotics,specification,urml,validator
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: Other/Proprietary License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.11
Requires-Dist: pydantic<3,>=2.6
Requires-Dist: pyyaml<7,>=6.0
Provides-Extra: dev
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-cov>=5; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
Description-Content-Type: text/markdown

<p align="center">
  <a href="https://urml.dev"><img src="https://urml.dev/favicon.svg" alt="URML" width="72" height="72"></a>
</p>

<p align="center">
  A small, opinionated, human-readable language for describing robot intent.
</p>

<p align="center">
  <a href="https://urml.dev"><b>urml.dev</b></a>
</p>

---

# Validator

**Status:** alpha, on PyPI as `urml-validator`. It ships the schemas, the six-pass validator, the `urml` CLI and JSON Schema export. Versions are `0.x`, so a release may break compatibility; the [changelog](https://github.com/urml-dev/URML/blob/main/CHANGELOG.md) says what each one changed. The LLM bridge and its on-device providers ship separately as `urml-llm-bridge`.

## What this is

The static verification engine for URML. Given a URML program, a Layer-1 capability manifest for the target robot, and the active safety envelope, the validator returns one of two outcomes:

1. **Accepted.** The program is statically valid, and the runtime may execute it.
2. **Rejected with a structured error.** The program fails one or more checks, and the error is a machine-readable object that a calling tool (often the LLM bridge) can use to revise the program.

The validator is **the safety boundary**. Per [`MANIFESTO.md`](https://github.com/urml-dev/URML/blob/main/MANIFESTO.md) §Design Principles and [`CLAUDE.md`](https://github.com/urml-dev/URML/blob/main/CLAUDE.md) §What Claude Should Never Do:

> *URML programs are executed only after static verification against the target's capability manifest and active safety envelope. Any "fast path" that skips verification is rejected on review.*

The validator runs in the same process as the runtime. `URMLRuntime.execute` imports it and re-validates every program, against the manifest, envelope, policy and rulebooks it is given, before its first adapter call. A rejected program raises `ValidationRejectedError` and the adapter receives nothing; `python -m urml_conformance --goal-line` checks this for every rejected conformance fixture. Skipping the check takes an explicit `revalidate=False` in code.

## What the validator checks

The validator runs these checks against every URML program. The specification asks for some checks the validator does not make; they are listed further down, under "What the validator does not check today".

### Layer-3 (composition) checks

- The program parses as valid URML against the layer-3 grammar.
- Every composition operator is well-formed (a `parallel` has at least two branches, a `retry` has a positive `max_attempts`, `on_error` is one of `abort_and_report`, `continue`, `retry`).
- Every `$variable` reference resolves to a prior `store_as`.
- Types match across producer/consumer primitives.

### Layer-2 (primitive) checks

- Every primitive is one the schema defines. An unknown primitive name is an `argument.*` error.
- Every primitive's required arguments are present and well-typed.
- Profile gates are honored: `drive` and `turn` need the `educational` profile, `look_at` and `gesture` need the `social` profile.

### Layer-1 (capability) checks

- The robot's manifest declares every capability the program needs (mobility, manipulation, perception, declared frames, declared locations).
- Every named place in the program resolves to a declared location or a declared area in the manifest.

### Safety-envelope checks

- Declared limits are checked on each step they apply to: velocity, altitude, grip force, the declared mass of an object a `move_to` carries, drop height, geofences with their altitude bands, people-occupancy zones, and the link-loss policy. For a numeric limit, the strictest of the manifest value and the envelope value applies.
- Spatial checks run on every place a step names (a pose, a declared location or area, a docking station, a scan area), whatever the profile. A geofence is an allowlist and a people-occupancy zone is a denylist.
- The checks judge the targets a program names. The runtime chooses the path between two targets, and the validator does not see it.

### Rulebook checks (RFC-0702, Draft)

- A rulebook states what law or a company allows: caps, forbidden primitives, forbidden zones, no flight over declared people zones, required deployment declarations, and how many aircraft fly at once. The format is [`spec/layer-1-hal/rulebook.md`](https://github.com/urml-dev/URML/blob/main/spec/layer-1-hal/rulebook.md).
- The rulebook pass runs after the envelope checks and cites the rule it enforces, with `rule.*` codes. `--no-policy` does not skip it.
- The bundled rulebook, the statically checkable subset of 14 CFR Part 107 and Part 89, applies by default to drone programs and aircraft. `--rulebook PATH` adds organization and deployment rulebooks; `--no-default-rulebooks` switches the bundled one off, with a warning.
- A deployment rulebook records declarations (such as the Remote ID method) and exceptions that name their basis (such as a waiver number). An exception turns a violation into a warning that names the basis. URML records these and does not verify them.
- Every report lists the rules a static check cannot see as obligations. A program that passes a rulebook is not a legal compliance determination.

```bash
urml validate flight.urml.yaml -m drone.manifest.yaml \
  --rulebook examples/rulebooks/example-deployment.yaml
```

## What the validator does NOT do

- It does not execute the program. That is the runtime's job.
- It does not parse natural language. That is the LLM bridge's job.
- It does not generate the URML program. That is an LLM's job, via the LLM bridge.
- It does not monitor runtime state. Run-time safety (an unexpected obstacle, a sudden wind gust, a person walking into the cell) is the substrate's job. The validator is **static**; the substrate is **dynamic**. Both are required for safety.

## Language

- **Python**, primary implementation. `mypy --strict`. Public API fully type-annotated.
- A long-running validator service (e.g., as a sidecar to multiple runtimes in production) may eventually be backed by **Rust** for deployment ergonomics; the Python implementation remains the reference.

## API

```python
from pathlib import Path

import yaml
from urml_validator import ValidationResult, validate


def load(name: str) -> dict:
    return yaml.safe_load(Path(name).read_text(encoding="utf-8"))


program = load("program.urml.yaml")    # parsed YAML; validate() does not take a YAML string
manifest = load("manifest.yaml")
envelope = load("envelope.yaml")

result: ValidationResult = validate(
    program,                # dict or URMLProgram
    manifest,               # dict or CapabilityManifest
    envelope,               # dict, SafetyEnvelope, or None
    profiles=("home",),     # the active profiles
    policy="DEFAULT",       # the bundled US-federal policy; None skips the policy pass
    rulebooks=(),           # organization and deployment rulebooks, parsed YAML
)

if result.accepted:
    print("accepted")       # hand the program to a runtime; URMLRuntime validates again before it acts
else:
    # result.errors is a list of structured errors,
    # designed to be readable by an LLM and used for revision.
    for err in result.errors:
        print(err.render())
```

The three file names are the ones `urml init` writes. `validate_fleet` does the same for a multi-robot program and a fleet roster.

## License

The validator is licensed under the Business Source License 1.1: free for non-production use, commercial license for production (see [`LICENSING.md`](https://github.com/urml-dev/URML/blob/main/LICENSING.md)). Research, education and evaluation use is free, so anyone can check a URML program against a manifest without a contract.

## Quickstart

From PyPI:

```bash
python -m venv .venv && . .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install urml-validator
urml --version
```

To run the tests, work from the root of a checkout. The suite also runs examples from the repository, and those import sibling packages, so install them alongside:

```bash
python -m venv .venv && . .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -e "reference/validator[dev]" -e reference/llm-bridge -e reference/ros2-runtime \
  -e reference/px4-runtime -e reference/ardupilot-runtime -e reference/opcua-runtime \
  -e reference/isaac-runtime -e conformance
cd reference/validator && pytest
```

The tests cover the schemas (the `red-mug` example parses; every primitive accepts its minimal valid form; cross-field rules fire, e.g. `move_to` requires exactly one of `location`/`pose`, `capture(media: video)` requires `duration`, `release(mode: place)` requires `at`), each validator pass, the policy and rulebook engines, the CLI and the evidence report.

What works today:

- Pydantic v2 schemas for Layer-1 (capability manifest), Layer-2 (the 12 core primitives of RFC-0002 and the profile primitives added since), Layer-3 (composition, including the fleet nodes `on` and `barrier`), the safety envelope, the compliance policy, the rulebook, the fleet roster and the top-level `URMLProgram`.
- The Step / BehaviorOrStep tagged union accepts the YAML surface (`{move_to: {...}}`) and the recursive composition forms.
- **The six-pass validator.** `urml_validator.validate(program, manifest, envelope, profiles)` runs the argument, capability, envelope, rulebook, binding and compliance-policy passes in that order and returns a `ValidationResult` with structured `ValidationError`s. Error codes are stable and namespaced (`argument.*`, `capability.*`, `envelope.*`, `rule.*`, `binding.*`, `policy.*`, and `fleet.*` from `validate_fleet`); the LLM bridge feeds them back to the model when it asks for a revision.
- Example:

  ```python
  from urml_validator import validate

  result = validate(program, manifest, envelope, profiles=("home",))
  if result.accepted:
      runtime.execute(program)
  else:
      for err in result.errors:
          print(err.render())
  ```

### `urml` CLI

Installing the package puts the `urml` console script on PATH. This example names files in the repository, so run it from the repository root:

```bash
urml validate examples/home/red-mug.urml.yaml \
  --manifest reference/validator/tests/fixtures/manifests/turtlebot4_home.yaml \
  --envelope reference/validator/tests/fixtures/envelopes/home_default.yaml \
  --profile home
```

Exit codes: **0** accepted, **1** validation failed, **2** usage error (missing file, bad YAML), **64** internal error.

Add `--json` to emit the raw `ValidationResult` for machine consumers (LLM bridge revision flow, CI checks).

Add `--evidence-log PATH` (on `validate`, `execute`, `translate` and `run`) to append one validation record per verdict to a local JSON Lines file. It is off by default and changes nothing the command prints. See [`docs/evidence/validation-records.md`](https://github.com/urml-dev/URML/blob/main/docs/evidence/validation-records.md).

`urml --help` lists the other subcommands: `init`, `execute`, `translate`, `run`, `bench`, `emit-prompt`, `schema`, `conformance run` and `evidence`. Some need a sibling package and say so when it is missing: `urml-llm-bridge` for `translate`, `run`, `bench` and `emit-prompt`, `urml-ros2-runtime` for `execute` and `run`, `urml-conformance` for `conformance run`.

### JSON Schema export

```bash
# Print one schema to stdout (suitable for piping into an LLM prompt fixture).
urml schema --name program

# Write every schema to a directory.
urml schema --all --out-dir build/schemas/
```

Produces Draft 2020-12 schemas for the program, the capability manifest, the safety envelope, the compliance policy, the fleet roster and the rulebook (`--name` takes `program`, `manifest`, `envelope`, `policy`, `roster` or `rulebook`). The LLM bridge consumes the program schema as the structured-output contract; robot makers consume the manifest schema when writing manifests by hand.

The Python API mirrors the CLI:

```python
from urml_validator import export_schema, write_schemas

schema = export_schema("program")  # dict
write_schemas(Path("build/schemas/"))  # writes one urml-<name>.schema.json per schema
```

What the validator does **not** check today:

- Definite assignment across `branch`, `parallel` and `retry`. A `$variable` counts as bound when its name is bound anywhere earlier in the program, even inside a branch that may not run.
- Field types inside a binding. `$ref.field` is accepted whenever the bound value is a structured payload; the field itself is not checked.
- Some profile rules the specification states. The drone profile makes an altitude mandatory on `move_to` and prohibits `wait` in flight, and the validator accepts both.
- Envelope limits that exist only at run time, such as weather, or that no manifest or envelope field carries. [`docs/safety/envelope-coverage.md`](https://github.com/urml-dev/URML/blob/main/docs/safety/envelope-coverage.md) lists, for each primitive, what is enforced and what is not.

## Related documents

- [`/spec/layer-1-hal/`](https://github.com/urml-dev/URML/tree/main/spec/layer-1-hal): manifest schema.
- [`/spec/layer-2-primitives/`](https://github.com/urml-dev/URML/tree/main/spec/layer-2-primitives): primitive contracts.
- [`/spec/layer-3-behavior/`](https://github.com/urml-dev/URML/tree/main/spec/layer-3-behavior): composition grammar.
- [`/reference/llm-bridge/`](https://github.com/urml-dev/URML/tree/main/reference/llm-bridge): the primary consumer of structured validation errors.
- [`/conformance/`](https://github.com/urml-dev/URML/tree/main/conformance): uses the validator as part of its end-to-end tests.
