类名:SchemaUtils

java.lang.Object
com.google.adk.SchemaUtils

public final class SchemaUtils extends Object
这是一个用于读取 JSON 数据并根据相关规范验证数据值的实用类(utility class)。
  • 方法概述

    Modifier and Type
    Method
    Description
    static boolean
    describesObject(com.google.genai.types.Schema schema)
    返回一个布尔值,表示是否…… schema 这是一个对象(object);其类型为“typed”。 OBJECT或者类型未知; 除非该对象具有某种已知的类型。 items 两者都不是。 properties nor required.
    findMismatch(@Nullable Object value, com.google.genai.types.Schema schema)
    返回原因(即为什么会发生某种情况)。 value 不匹配。 schema如果该值不存在,则返回空字符串;如果该值存在,则返回其实际值。
    static @Nullable Object
    parseModelOutput(String output, com.google.genai.types.Schema schema)
    根据……解析模型文本。 schema 该函数可以将数据作为 JSON 值返回;如果返回 JSON 值失败(且数据格式符合指定的规范),则会直接返回文本本身(前提是该规范允许使用字符串类型的数据)。
    static void
    validateMapOnSchema(Map<String,Object> args, com.google.genai.types.Schema schema, Boolean isInput)
    根据指定的模式验证一个映射(map)的结构是否合法。
    static @Nullable Object
    validateOutput(String output, com.google.genai.types.Schema schema)
    解析(数据) output 然后根据某些标准对其进行验证(即检查其是否符合要求)。 schema.
    static Map<String,Object>
    validateOutputSchema(String output, com.google.genai.types.Schema schema)
    根据指定的模式验证输出字符串的有效性。

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 方法详细信息(Method Details)

    • validateMapOnSchema

      public static void validateMapOnSchema(Map<String,Object> args, com.google.genai.types.Schema schema, Boolean isInput)
      根据指定的模式验证一个映射(map)的结构是否合法。
      Parameters:
      args - The map to validate.
      schema - The schema to validate against.
      isInput - Whether the map is an input or output.
      Throws:
      IllegalArgumentException - If the map does not match the schema.
    • parseModelOutput

      public static @Nullable Object parseModelOutput(String output, com.google.genai.types.Schema schema)
      根据……解析模型文本。 schema 该函数应该以 JSON 值的形式返回数据;如果返回数据失败(即无法满足数据结构的要求),且数据结构允许字符串类型作为输入,则应直接返回该字符串本身。数据结构同时允许空字符串(即 “”)和 JSON 中的 `null` 值。 null.

      此方法仅适用于代理开发工具包(Agent Development Kit)。

      Throws:
      IllegalArgumentException - if the text does not match the schema
    • findMismatch

      public static Optional<String> findMismatch(@Nullable Object value, com.google.genai.types.Schema schema)
      返回原因(即为什么会发生某种情况)。 value 不匹配。 schema如果该字段不存在,则其值为空。之所以这样设计,是因为这些字段只是数据库模式的一部分(即它们仅用于定义数据的结构),而实际的数据值是由用户提供的。

      此方法仅适用于代理开发工具包(Agent Development Kit)。

    • describesObject

      public static boolean describesObject(com.google.genai.types.Schema schema)
      返回一个布尔值,表示是否…… schema 这是一个对象(object);其类型为“typed”。 OBJECT或者类型未知; 除非该对象具有某种已知的类型。 items 两者都不是。 properties nor required.

      此方法仅适用于代理开发工具包(Agent Development Kit)。

    • validateOutput

      public static @Nullable Object validateOutput(String output, com.google.genai.types.Schema schema) throws com.fasterxml.jackson.core.JsonProcessingException
      解析(数据) output 然后根据某些标准对其进行验证(即检查其是否符合要求)。 schema一个对象模式(object schema)需要经过一定的处理或转换过程才能被使用。 validateOutputSchema(String, Schema)对于数组或基本数据类型的结构(schema),该方法会返回解析后的值(例如一个列表),该值可能为 `null`。

      此方法仅适用于代理开发工具包(Agent Development Kit)。

      Throws:
      IllegalArgumentException - If the output does not match the schema.
      com.fasterxml.jackson.core.JsonProcessingException - If the output cannot be parsed.
    • validateOutputSchema

      public static Map<String,Object> validateOutputSchema(String output, com.google.genai.types.Schema schema) throws com.fasterxml.jackson.core.JsonProcessingException
      根据指定的模式验证输出字符串的有效性。
      Parameters:
      output - The output string to validate.
      schema - The schema to validate against.
      Returns:
      The output map.
      Throws:
      IllegalArgumentException - If the output string does not match the schema.
      com.fasterxml.jackson.core.JsonProcessingException - If the output string cannot be parsed.