Creating a deterministic evaluator

Create a custom deterministic evaluator in Cloudera Agent Studio that applies fixed, rule-based checks to the traces or sessions of an agent, without a language model.

A deterministic evaluator runs checks that return the same result for the same evidence. You define the evidence that the evaluator reads, which are the extractors, and the rules that the evaluator applies to that evidence, which are the checks. Agent Studio saves the evaluator as a versioned custom evaluator. After you save it, you can select it when you run an evaluation.

The name of the evaluator identifies it across versions, and the display name is the name that users see. If you save an evaluator with the name of an existing evaluator and the content is different, Agent Studio creates a new version. If the content is identical to an existing version, Agent Studio does not create a new version.

The New deterministic evaluator page has the following sections:

  • Details: The Display name, Name, and Description of the evaluator.
  • Scope and coverage: The evidence scopes that the evaluator supports and the Coverage policy.
  • Evaluator definition: The Import definition JSON file picker and the collapsible Definition JSON text area. You can import or paste a definition, or you can build the definition in the Extractors and Checks sections.
  • Extractors: The named evidence sources that the checks read from.
  • Checks: The rules that run against one or more extractors. Each check contributes an assessment to the run.

In Scope and coverage, you select the evidence scopes and the coverage policy:

  • Trace: The evaluator runs checks against single-trace evidence. This scope is selected by default.
  • Session: The evaluator runs checks against session-level evidence.
  • Require all extractors: The run fails if a required extractor cannot be populated. This policy is selected by default.
  • Allow partial coverage: The evaluator can run when some extractors cannot be populated.

Each extractor has one of the following types:

  • Final output: The text that the agent returned to the user.
  • Tool arguments (not available yet): The arguments that the agent passed to a tool. The type is unavailable.
  • Tool results (not available yet): The structured results of a tool call. The type is unavailable.
  • Call log: The ordered tool-call and delegation events of the trace.
  • Span log: The span-level log lines of the trace.

The cardinality of an extractor defines how many matches the extractor keeps:

  • all: Keep every match. The Call log and Span log types always use all.
  • exactly_one: Fail if no match or more than one match exists.
  • first: Use the first match in trace order.
  • last: Use the last match in trace order.

Each check has one of the following types:

  • Syntax: Parses extracted SQL or Python text.
  • AST policy: Applies SQL or PySpark syntax-tree rules, such as allowed statements and forbidden nodes.
  • Embedded syntax: Checks SQL that is embedded in PySpark call sites.
  • JSON schema: Validates JSON against a schema from the expectations of the test case or from a snapshot.
  • Schema snapshot: Compares the shape of extracted JSON with an expected snapshot.
  • SQL lineage: Compares the tables that parsed SQL references with the expected tables.
  • Value compare: Compares a scalar value with the value at the expectations path.
  • Table compare: Compares the rows and columns of tabular tool output.
  • Set relation: Checks whether two sets of values are equal, or whether one is a subset or a superset of the other, or whether they are disjoint.
  • Text contains: Checks whether extracted text contains a substring or a token.
  • Number in text: Compares the numbers in prose with the expected numbers.
  • Count: Compares the number of tool calls, delegations, human-in-the-loop pauses, or plans with an expected limit.
  • Uniqueness: Detects duplicate tool calls by selected key fields.
  • Sequence: Compares the ordered tool calls or delegations with an expected sequence.
  • Presence: Checks whether a plan, a delegation, or a human-in-the-loop pause occurred.
  • Error rate: Limits the share of spans or tool spans that have errors.

Each check has a gating value. A check with the Required gating value blocks a pass when the check fails. A check with the Advisory gating value reports a signal and does not fail the run.

Each check returns one of the following statuses: PASS, FAIL, UNSCORABLE, PREMISE_UNMET, or SKIPPED.

  • Plan the extractors and the checks. A definition has the following structure:
    • schema_version: The value is always deterministic-evaluator-v1.
    • supported_scopes: ["trace"], ["session"], or ["trace","session"].
    • coverage_policy: require_all or allow_partial.
    • extractors: An object of 1 to 32 extractors. The key of each extractor is its reference name. Each extractor has the fields type, version, cardinality, and required. A tool extractor also has the fields role and field. A Final output extractor can have the field language.
    • checks: An array of 1 to 64 checks. Each check has the fields id, type, version, inputs, depends_on, gating, params, and expectation_path.
  • Ensure that the definition is 256 KiB or smaller.
  • Optional: To import a definition, save the definition in a file with the extension .json. A check can depend only on checks that precede it in the checks array. The New deterministic evaluator page does not set depends_on, so use an imported definition to set it.
  • Optional: To compare a value with the expected result of a test case, add the expectations object to the test cases of your test set. See Creating a test set.
  • Ensure each serialized test case, including its expectations object, is 256 KiB or smaller.
  • Note the run limits. A check runs for up to 5 seconds, and all the checks of an evaluator run for up to 30 seconds.
To create a deterministic evaluator:
  1. Launch the Cloudera Agent Studio console.
  2. In the left navigation pane, click Evaluations.
    The Runs tab is displayed.
  3. Click the Evaluators tab, and then click the Deterministic sub-tab.
    The Built-in evaluators and Custom evaluators sections are displayed.
  4. Click New deterministic evaluator.
    The New deterministic evaluator page is displayed.
  5. In the Details section, enter the details of the evaluator.
    1. In Display name, enter the name that users see.
      Agent Studio suggests a value for Name from the display name until you edit Name.
    2. In Name, enter the name that identifies the evaluator across versions.
      If you already saved an evaluator with this name, the hint You already saved v<number>; changed content saves as v<number>. is displayed, with the current and the next version numbers.
    3. In Description, enter the description of the evaluator.
  6. In the Scope and coverage section, select the scopes and the coverage policy.
    1. In Evidence scope, click Trace, Session, or both.
      You cannot clear the last selected scope.
    2. In Coverage policy, click Require all extractors or Allow partial coverage.
  7. Optional: To start from an existing definition, in the Evaluator definition section, import or paste the definition.
    • To import a file, click Import definition JSON, and then select the file.

      The message Imported definition is displayed, and the Extractors and Checks sections contain the values of the file.

    • To paste the definition, click Definition JSON, and then paste the JSON in the text area.

      The text area is labeled Paste JSON or edit after import. When the JSON is valid, the page merges it into the Extractors and Checks sections. When you change a row, the page updates the JSON. If the page cannot read the text, the alert Could not parse definition JSON is displayed.

  8. In the Extractors section, define the evidence sources.
    The section contains one extractor, Extractor 1, with the reference name call-log, the type Call log, and Required for coverage selected.
    1. In Reference name, enter the name of the extractor, for example final-answer.
    2. In Type, click Final output, Call log, or Span log.
    3. For a Final output extractor, in Cardinality, click all, exactly_one, first, or last. The field is not displayed for Call log and Span log, because those types use all.
    4. To make the run depend on the extractor, select Required for coverage.
    5. Optional: For a Final output extractor, in Language hint (optional), enter the language of the text, for example sql, python, json, yaml, or text.
    6. To add an extractor, click Add extractor, and then repeat steps 1 to 5 in the new row.
    7. To delete an extractor, click Remove in the row of the extractor.
      The link is unavailable when only one extractor remains. The page displays the note At least one extractor is required; add another to enable Remove on a row.
  9. In the Checks section, define the rules.
    The section contains one check, Check 1, with the reference name max-steps, the type Count, the count Tool calls, the comparison At most, the gating Advisory, and the expectations path /expect/max_steps.
    1. In Reference name, enter the name of the check, for example tool-call-limit.
    2. In Check type, click the type of the check.
    3. In Extractor inputs, click the extractors that the check reads.
      • To select every extractor, click Select all.
      • To reverse the selection, click Invert selection.
      • To clear the selection, click Clear.
    4. In Gating, click Advisory or Required.
    5. Optional: In Expectations path (optional), enter an RFC 6901 pointer into the expectations object of a test case, for example /expect/max_steps.
    6. Set the fields of the check type.
      • Count:
        • In Count, click Tool calls, Delegations, HITL, or Plans.
        • In Comparison, click Equals, At most, or At least.
        • In Expected, enter a whole number. Leave the field empty to read the limit from the expectations path.
      • Syntax:
        • In Engine, click SQL or Python.
        • For SQL, in SQL dialect, enter the parser dialect, for example ansi, spark, or trino.
      • Text contains:
        • In Match, click All phrases or Any phrase.
        • To match letter case, select Case sensitive.
        • To collapse runs of spaces and new lines before matching, select Normalize whitespace. This option is selected by default.
      • Value compare:
        • In Comparison, click Equal or Not equal.
        • In Null handling, click Nulls equal, Nulls unequal, or Nulls unscorable.
      • Presence:
        • In Event, click Plan, Delegation, or HITL. The Tool role (not available yet) option is unavailable.
        • To require that the event does not occur, clear Expected to occur.
      • Error rate:
        • In Scope, click All spans or Tool spans.
        • In Max error rate (0–1), enter a number from 0 to 1. For example, 0.1 is 10 percent.
      • SQL lineage: In SQL dialect, enter the dialect that parses the tables of the extracted SQL.
      • Schema snapshot: In Mode, click Exact or Subset.
      • Set relation:
        • In Relation, click Equal, Subset, Superset, or Disjoint.
        • In Canonicalization, click None, Casefold strings, or Stable JSON.
      • Sequence:
        • In Select, click Tool calls or Delegations.
        • In Mode, click Exact or Ordered subsequence.
      • JSON schema: The check has no other parameters. Provide the expected JSON schema through the expectations path.
      • AST policy, Embedded syntax, Table compare, Number in text, and Uniqueness: The page displays the alert Advanced check type. To edit the parameters of these types, import a validated definition file.
    7. To add a check, click Add check, and then repeat steps 1 to 6 in the new row.
    8. To delete a check, click Remove in the row of the check.
      The link is unavailable when only one check remains.
    If the structure of the definition has errors, the alert Definition needs attention lists them while you edit.
  10. Click Save.
    To leave the page without saving, click Cancel, or click Evaluations at the top of the page.
To review a deterministic evaluator:
  1. Launch the Cloudera Agent Studio console.
  2. In the left navigation pane, click Evaluations, click the Evaluators tab, and then click the Deterministic sub-tab.
  3. In the Custom evaluators section, in the row of the evaluator, click Open menu, and then click View evaluator.
    The page of the evaluator opens. The title has the format <display name> · v<version>. The description is: Read-only view of extractors, checks, and definition for this evaluator version.
  4. Review the sections of the page.
    • Evaluator details and Versions: The details and the saved versions of the evaluator.
    • Evaluator definition: The Extractors and the Checks of the version. Each check displays its gating, its Extractor inputs, Depends on, and Parameters.
    • Definition JSON: The definition as JSON. To copy the JSON, click Copy definition JSON.

After you save the evaluator, the Deterministic sub-tab of the Evaluators tab opens, and one of the following messages is displayed:

  • Saved deterministic evaluator v<version>: Agent Studio saved the evaluator as a new version.
  • Deterministic evaluator unchanged (v<version>): The content is identical to an existing version, and Agent Studio did not create a new version.

The evaluator is displayed in the Custom evaluators section. To use the evaluator, select it in the Evaluators section of the New run page. See Running an evaluation.

If the save fails, the alert Fix these issues before saving lists each error, and the message Fix the errors listed on this page, then save again. is displayed.