1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//! Opt-in, partial validation of parsed protocol values.
//!
//! Select one contract namespace: [`openai`], [`vllm`], or [`sglang`]. Each
//! namespace exposes field helpers and a request trait for the covered request
//! types. The engine namespaces reuse the OpenAI operation where the engine
//! matches it and define an override where it differs. Engine contracts are not
//! supersets of OpenAI, so do not run the OpenAI checks before an engine's checks.
//!
//! All operations in this module follow the same contract:
//!
//! - They are read-only. They never mutate, normalize, insert defaults, or dispatch.
//! - Field helpers are named `validate_<field>` and take the request field's
//! parsed type. `None` (omitted or null at the typed boundary) always succeeds.
//! - Float helpers reject NaN and infinities. They check parsed `f32` values and do
//! not reproduce JSON coercion, null admission, or backend HTTP diagnostics.
//! - Request traits run their covered checks in a documented order and return the
//! first failure. Success does not establish complete endpoint admission.
//!
//! Coverage and known gaps are tracked in the temporary
//! [coverage tracker](https://github.com/ai-dynamo/frontend-crates/blob/main/protocols/src/validation/coverage.md).
//!
//! ```rust
//! use dynamo_protocols::{
//! normalization,
//! types::CreateCompletionRequest,
//! validation::{openai::OpenAIValidation, vllm::VllmValidation},
//! };
//!
//! let mut request = CreateCompletionRequest {
//! logprobs: Some(10),
//! ..Default::default()
//! };
//! normalization::vllm::normalize_completion_logprobs(&mut request.logprobs);
//! // vLLM accepts 10 completion logprobs; the OpenAI baseline allows at most 5.
//! assert!(VllmValidation::validate(&request).is_ok());
//! assert!(OpenAIValidation::validate(&request).is_err());
//! assert_eq!(request.logprobs, Some(10));
//! ```
//!
//! A server still owns prompt, model, runtime, and other admission checks.
// Operations that vLLM and SGLang implement equivalently outside the OpenAI
// contract. Private: consumers reach them through an engine namespace.
/// A library diagnostic for the first failed covered check.
///
/// `Display` renders `"{message}, got {value}"`. The error carries no HTTP status
/// or backend exception metadata; consumers select their own transport mapping.
/// Accepts `None` or a value for which `accepted` returns true.
/// Builds the diagnostic only on failure.