ForkAnthropicAnthropicpublished Sep 24, 2026seen 4w

anthropics/serde-saphyr

forked from bourumir-wyngs/serde-saphyr

Open original ↗

Captured source

source ↗
published Sep 24, 2026seen 4wcaptured 4whttp 200method plain

anthropics/serde-saphyr

Description: A strongly typed, comment-supporting YAML deserializer that deserializes YAML directly into your Rust types without constructing an intermediate tree of “abstract values.”

License: Apache-2.0

Stars: 1

Forks: 0

Open issues: 0

Created: 2026-09-24T17:55:53Z

Pushed: 2026-09-24T19:08:04Z

Default branch: master

Fork: yes

Parent repository: bourumir-wyngs/serde-saphyr

Archived: no

README:

serde-saphyr

![Miri](https://github.com/bourumir-wyngs/serde-saphyr/actions/workflows/miri.yml) ![docs.rs](https://docs.rs/serde-saphyr) ![codecov](https://codecov.io/gh/bourumir-wyngs/serde-saphyr)

![Fuzz & Audit](https://github.com/bourumir-wyngs/serde-saphyr/actions/workflows/ci.yml) ![1.3 API compatibility](https://github.com/bourumir-wyngs/serde-saphyr/actions/workflows/api-compat.yml)

![Socket](https://socket.dev/cargo/package/serde-saphyr) ![dependency status](https://deps.rs/crate/serde-saphyr/latest)

serde-saphyr is a strongly typed YAML deserializer built on top of `granit-parser`.

The parser is fuzz-tested and designed not to panic on malformed YAML. This design does not cover out-of-memory conditions, panics in user-provided callbacks, or similar cases. The library build is configured to deny unsafe code. This does not extend to transitive dependencies.

The crate deserializes YAML *directly into your Rust types* without constructing an intermediate tree of “abstract values.” Try it online as a WebAssembly application here.

See release history on GitHub.

Overview

Why this approach?

  • Light on resources: Having almost no intermediate data structures should result in more efficient parsing, especially if anchors are used only lightly.
  • Also, simpler: No code to support intermediate Values of all kinds.
  • Type-driven parsing: YAML that doesn’t match the expected Rust types is rejected early.
  • Safer by construction: serde-saphyr avoids the typical YAML remote code execution vulnerability because it does not support or implement tag-driven object construction. When used for linting, it can be configured to reject unknown tags.

Notable features

  • Configurable budgets: Enforce input limits to mitigate resource exhaustion (e.g., deeply nested structures or very large arrays); see `Budget`.
  • Precise error reporting with snippet rendering.
  • Optional !include support with a custom or default resolver (inclusion of either a complete document or the node referenced by a specified anchor).
  • Tag support: The `Tagged` wrapper captures and emits a node's resolved YAML tag.
  • Comment support. Wrapper `Commented` both captures and emits comments.
  • Optional property support, with redaction (removal) of property values from crate-generated diagnostics.
  • Serializer supports emitting anchors (Rc, Arc, Weak) if they are properly wrapped (see below).
  • Declarative validation with optional [`validator`](https://crates.io/crates/validator) ([example](https://github.com/bourumir-wyngs/serde-saphyr/blob/master/examples/validator_validate.rs)) or [`garde`](https://crates.io/crates/garde) (example).
  • Optional [`miette`](https://crates.io/crates/miette) (example) integration for more advanced error reporting.
  • serde_json::Value is supported when parsing without target structure defined (non-finite values are rejected for floats).
  • [Serializer](https://docs.rs/serde-saphyr/latest/serde_saphyr/struct.Serializer.html) and [Deserializer](https://docs.rs/serde-saphyr/latest/serde_saphyr/struct.Deserializer.html) are public (due to how it's implemented, Deserializer is available in the closure only).
  • Serialized floats are official YAML floats.
  • Correct handling for JSON-style Unicode surrogate pairs.
  • robotic extensions to support YAML dialect common in robotics (see below).

serde-saphyr is compatible with WebAssembly. The CI flow includes builds for both wasm32-unknown-unknown (browser / JS) and wasm32-wasip1 (WASI runtimes), with most of the test suite running and passing (excluding tests that require file access or similarly unsupported functionality). We also wrote yva in Dioxus to deploy serde-saphyr on the web.

Testing

The test suite currently includes over 3000 passing tests. For YAML Test Suite v2022-01-17, all 350 active test IDs and all 402 active cases from the `data-2022-01-17` release are represented (9C9N is intentionally relaxed to keep the library compatible with PyYAML and ruamel.yaml). Although we made a reasonable effort, accidental omissions or conversion errors remain possible. Some additional cases are taken from the original serde-yaml tests.

Project relationship

serde-saphyr is not a fork of the older `serde-yaml` crate and shares no code with it (apart from some reused tests). It is also not part of the `saphyr` project. The name was historically chosen to reflect the use of saphyr parser at a time when the Saphyr project did not provide its own Serde integration. granit-parser it's currently using is the fork of...

Excerpt shown — open the source for the full document.