Skip to main content

switchyard_libsy/core/
outcome_metadata.rs

1// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Metadata describing a routing outcome.
5
6use serde_json::Value;
7
8/// Identity and optional algorithm evidence attached to a successful routing outcome.
9#[derive(Clone, Debug, PartialEq, Eq)]
10pub struct OutcomeMetadata {
11    outcome_id: String,
12    /// Stable name of the algorithm that produced the outcome.
13    pub algorithm: String,
14    /// Optional algorithm-defined JSON evidence.
15    ///
16    /// Built-in algorithms emit an object with a stable `source` string and only the
17    /// relevant `score`, `confidence`, `threshold`, `verdict`, `trigger`, or `reason_code`
18    /// fields. Not every algorithm or decision produces evidence.
19    pub evidence: Option<Value>,
20}
21
22impl OutcomeMetadata {
23    /// Creates outcome metadata with a new UUIDv7 identifier.
24    pub fn new(algorithm: String, evidence: Option<Value>) -> Self {
25        Self {
26            outcome_id: uuid::Uuid::now_v7().to_string(),
27            algorithm,
28            evidence,
29        }
30    }
31
32    /// Returns the unique identifier for this outcome.
33    pub fn outcome_id(&self) -> &str {
34        &self.outcome_id
35    }
36}