Repository navigation
Description
概述
ToolValidator.validateInput 使用 networknt json-schema-validator(版本 2.0.0)做工具入参校验时,失败后返回的错误信息丢失了字段名称/路径,只保留了 message 本身。当多个字段同时校验失败时,返回结果是一串完全相同的 message,无法定位具体是哪个字段出了问题。
影响范围:所有调用 ToolValidator.validateInput 的工具入参校验场景。
相关源码:io.agentscope.core.tool.ToolValidator(validateInput 方法)。
问题描述
validateInput 在拿到校验结果后,只调用了 Error::getMessage 来拼装错误信息:
// Create Schema from the schema string
Schema jsonSchema = SCHEMA_REGISTRY.getSchema(schemaJson);
String normalizedInput = normalizeOptionalNullFields(input, schemaJson);
// Validate
List<Error> errors = jsonSchema.validate(normalizedInput, InputFormat.JSON);
if (errors.isEmpty()) {
return null; // Validation passed
}
// Format error messages
return errors.stream().map(Error::getMessage).collect(Collectors.joining("; "));
networknt 的 Error 对象本身已经携带了出错字段的位置信息(getInstanceLocation(),返回 com.networknt.schema.path.NodePath),但 getMessage() 只返回 message(本地化文案),例如 已找到 null,必须是 string,不包含字段路径。代码在 map(Error::getMessage) 这一步把位置信息丢掉了。
结果是:当入参有 N 个字段校验失败时,返回的是 N 条一模一样的 message 拼接串,无法区分是哪 N 个字段。
根因分析
Error.getMessage()只返回关键字级别的本地化文案(由 message bundle 提供),不含 instance location。Error.getInstanceLocation()才指向具体出错字段(对应 JSON 中的路径,如/response/awards/0/awardLevel)。- 现有代码只用
getMessage(),未拼装getInstanceLocation(),因此丢失字段名。
复现步骤
使用下面「测试用例」中的两个文件,对 content 执行 schema 校验:
public static void main(String[] args) throws Exception {
String input = Files.readString(Path.of("tool-validator-error-content.json"));
String schemaJson = Files.readString(Path.of("tool-validator-error-schema.json"));
Schema jsonSchema = SCHEMA_REGISTRY.getSchema(schemaJson);
String normalizedInput = normalizeOptionalNullFields(input, schemaJson);
List<Error> errors = jsonSchema.validate(normalizedInput, InputFormat.JSON);
// 当前实现只打印 getMessage(),丢失字段路径
System.out.println(errors.stream().map(Error::getMessage).collect(Collectors.joining("; ")));
}
测试用例
说明:本例的 40 个校验失败均由「
required的string字段值为null」触发,与具体字符串值(姓名、邮箱等)无关,因此脱敏后的内容文件仍可稳定复现同样的 40 个错误。
待校验内容(tool-validator-error-content.json)
{
"response" : {
"additionalQuestions" : {
"majorDiseaseOrFamilyGeneticHistory" : null,
"majorViolationsOrCriminalInvolvement" : null,
"personalBusinessOperation" : "否"
},
"attachments" : [ ],
"awards" : [ {
"awardLevel" : null,
"awardName" : "优秀毕业生",
"awardingOrganization" : null,
"certifier" : null,
"obtainedDate" : null
}, {
"awardLevel" : null,
"awardName" : "学业一等奖学金",
"awardingOrganization" : null,
"certifier" : null,
"obtainedDate" : null
}, {
"awardLevel" : null,
"awardName" : "优秀学生",
"awardingOrganization" : null,
"certifier" : null,
"obtainedDate" : null
}, {
"awardLevel" : null,
"awardName" : "第八届全国大学生数字媒体科技作品及创意竞赛三等奖",
"awardingOrganization" : null,
"certifier" : null,
"obtainedDate" : null
}, {
"awardLevel" : null,
"awardName" : "微信小程序应用开发赛华东赛区二等奖",
"awardingOrganization" : null,
"certifier" : null,
"obtainedDate" : null
} ],
"basicInfo" : {
"acceptTransfer" : "是",
"birthDate" : "2000-01-01",
"countryOrRegion" : "中国",
"employmentStatus" : null,
"ethnicity" : "汉族",
"formalWorkExperience" : "否",
"gender" : "男",
"graduationDate" : "2026-07-01",
"height" : "175",
"highestEducation" : "硕士研究生",
"householdLocation" : "北京市",
"maritalStatus" : "未婚",
"name" : "张三",
"nativePlace" : "北京市",
"overseasEducation" : null,
"politicalStatus" : "中国共产党党员(含预备党员)",
"preEnrollmentHouseholdLocation" : null,
"preEnrollmentHouseholdType" : null,
"weight" : "68",
"workYears" : null
},
"campusActivities" : [ ],
"certificates" : [ ],
"companyRelative" : {
"department" : null,
"hasCompanyRelative" : "否",
"name" : null,
"relationship" : null,
"requiresRecusal" : null
},
"contactInfo" : {
"email" : "[email protected]",
"phone" : "13800138000",
"postalCode" : null,
"residentialAddress" : "北京市朝阳区测试路1号"
},
"educations" : [ {
"degree" : "硕士",
"endDate" : "2026-07",
"fullGpa" : "4.00",
"fullTime" : "是",
"gpa" : "3.80",
"gradeRanking" : "前10%",
"hasRetake" : null,
"major" : "计算机科学与技术",
"retakeSubjects" : null,
"school" : "测试大学",
"schoolLocation" : "北京市",
"startDate" : "2023-08",
"studyMode" : "统招全日制"
}, {
"degree" : "本科",
"endDate" : "2022-07",
"fullGpa" : "4.00",
"fullTime" : "是",
"gpa" : "3.80",
"gradeRanking" : "前10%",
"hasRetake" : null,
"major" : "计算机科学与技术",
"retakeSubjects" : null,
"school" : "测试大学",
"schoolLocation" : "北京市",
"startDate" : "2018-08",
"studyMode" : "统招全日制"
} ],
"familyInformation" : [ ],
"identityInfo" : {
"documentNumber" : "110101200001011234",
"documentType" : "身份证",
"nationality" : "中国"
},
"jobIntention" : {
"availableDate" : null,
"currentLocation" : "北京市",
"desiredCity" : "朝阳区, 海淀区",
"expectedSalary" : null
},
"languageSkills" : [ ],
"lifePhotos" : [ ],
"practiceExperiences" : [ ],
"professionalSkills" : [ ],
"projectExperiences" : [ ],
"selfEvaluation" : null,
"specialtiesAndInterests" : null,
"trainingExperiences" : [ ],
"workExperiences" : [ ]
}
}
JSON Schema(tool-validator-error-schema.json)
{
"$defs" : {
"Attachment" : {
"type" : "object",
"properties" : {
"description" : {
"type" : "string",
"description" : "附件说明;无原文返回null"
},
"name" : {
"type" : "string",
"description" : "附件名称"
},
"url" : {
"type" : "string",
"description" : "附件地址或链接;无原文返回null"
}
},
"required" : [ "description", "name", "url" ]
},
"ActivityExperience" : {
"type" : "object",
"properties" : {
"description" : {
"type" : "string",
"description" : "活动或实践内容描述;无原文返回null"
},
"endDate" : {
"type" : "string",
"description" : "结束时间,优先YYYY-MM;仍在进行时返回null"
},
"organization" : {
"type" : "string",
"description" : "组织或单位名称"
},
"position" : {
"type" : "string",
"description" : "担任职务;无原文返回null"
},
"startDate" : {
"type" : "string",
"description" : "开始时间,优先YYYY-MM"
}
},
"required" : [ "description", "endDate", "organization", "position", "startDate" ]
}
},
"type" : "object",
"properties" : {
"response" : {
"type" : "object",
"properties" : {
"additionalQuestions" : {
"type" : "object",
"properties" : {
"majorDiseaseOrFamilyGeneticHistory" : {
"type" : "string",
"description" : "是否曾患过重大疾病或有家族遗传病史;无原文返回null"
},
"majorViolationsOrCriminalInvolvement" : {
"type" : "string",
"description" : "是否有过重大违法违规违纪或涉黑涉恶等情况;无原文返回null"
},
"personalBusinessOperation" : {
"type" : "string",
"description" : "个人是否有经商办;无原文返回null"
}
},
"required" : [ "majorDiseaseOrFamilyGeneticHistory", "majorViolationsOrCriminalInvolvement", "personalBusinessOperation" ],
"description" : "补充问题;无原文时可返回null"
},
"attachments" : {
"description" : "其他附件列表;无则返回空数组",
"type" : "array",
"items" : {
"$ref" : "#/$defs/Attachment",
"description" : "其他附件列表;无则返回空数组"
}
},
"awards" : {
"description" : "获奖列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"awardLevel" : {
"type" : "string",
"description" : "奖项级别;无原文返回null"
},
"awardName" : {
"type" : "string",
"description" : "获奖名称"
},
"awardingOrganization" : {
"type" : "string",
"description" : "授予单位;无原文返回null"
},
"certifier" : {
"type" : "string",
"description" : "证明人;无原文返回null"
},
"obtainedDate" : {
"type" : "string",
"description" : "获得时间;无原文返回null"
}
},
"required" : [ "awardLevel", "awardName", "awardingOrganization", "certifier", "obtainedDate" ],
"description" : "获奖列表;无则返回空数组"
}
},
"basicInfo" : {
"type" : "object",
"properties" : {
"acceptTransfer" : {
"type" : "string",
"description" : "是否接受岗位调剂;当前样例页未展示该栏,有原文则提取,无则返回null"
},
"birthDate" : {
"type" : "string",
"description" : "出生日期,优先YYYY-MM-DD格式"
},
"countryOrRegion" : {
"type" : "string",
"description" : "候选人本人的所在国家或地区,不是海外院校所在国家"
},
"employmentStatus" : {
"type" : "string",
"description" : "当前就业状态,如在职、离职、应届生"
},
"ethnicity" : {
"type" : "string",
"description" : "民族原文值"
},
"formalWorkExperience" : {
"type" : "string",
"description" : "是否有正式工作经历,不将实习认定为正式工作"
},
"gender" : {
"type" : "string",
"description" : "性别原文值;无原文依据返回null"
},
"graduationDate" : {
"type" : "string",
"description" : "最高学历毕业日期,不是其他学历毕业日期"
},
"height" : {
"type" : "string",
"description" : "身高数值,单位厘米,使用字符串表示"
},
"highestEducation" : {
"type" : "string",
"description" : "最高学历,如本科、硕士研究生、博士研究生"
},
"householdLocation" : {
"type" : "string",
"description" : "户口或户籍所在地;原文没有时可用籍贯兜底,禁止使用现居住地或学校所在地"
},
"maritalStatus" : {
"type" : "string",
"description" : "婚姻状况原文值"
},
"name" : {
"type" : "string",
"description" : "候选人姓名;无原文依据返回null"
},
"nativePlace" : {
"type" : "string",
"description" : "籍贯原文值"
},
"overseasEducation" : {
"type" : "string",
"description" : "是否有中国大陆以外(含港澳台)教育经历,只能填是、否或null"
},
"politicalStatus" : {
"type" : "string",
"description" : "政治面貌原文值"
},
"preEnrollmentHouseholdLocation" : {
"type" : "string",
"description" : "入学前户口所在地,只提取原文明确值"
},
"preEnrollmentHouseholdType" : {
"type" : "string",
"description" : "入学前户口性质,如城镇或农村"
},
"weight" : {
"type" : "string",
"description" : "体重数值,单位千克,使用字符串表示"
},
"workYears" : {
"type" : "string",
"description" : "正式工作年限,不含普通实习经历"
}
},
"required" : [ "acceptTransfer", "birthDate", "countryOrRegion", "employmentStatus", "ethnicity", "formalWorkExperience", "gender", "graduationDate", "height", "highestEducation", "householdLocation", "maritalStatus", "name", "nativePlace", "overseasEducation", "politicalStatus", "preEnrollmentHouseholdLocation", "preEnrollmentHouseholdType", "weight", "workYears" ],
"description" : "基础信息;无原文依据时各字段可为null,模块本身也可为null"
},
"campusActivities" : {
"description" : "校园活动列表;无则返回空数组",
"type" : "array",
"items" : {
"$ref" : "#/$defs/ActivityExperience",
"description" : "校园活动列表;无则返回空数组"
}
},
"certificates" : {
"description" : "资格证书列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"certificateName" : {
"type" : "string",
"description" : "证书名称"
},
"issuingAuthority" : {
"type" : "string",
"description" : "颁发机构;无原文返回null"
},
"obtainedDate" : {
"type" : "string",
"description" : "取得时间;无原文返回null"
}
},
"required" : [ "certificateName", "issuingAuthority", "obtainedDate" ],
"description" : "资格证书列表;无则返回空数组"
}
},
"companyRelative" : {
"type" : "object",
"properties" : {
"department" : {
"type" : "string",
"description" : "亲属所在部门;无原文返回null"
},
"hasCompanyRelative" : {
"type" : "string",
"description" : "是否有本单位亲属,只能填是、否或null"
},
"name" : {
"type" : "string",
"description" : "亲属姓名;无原文返回null"
},
"relationship" : {
"type" : "string",
"description" : "与本人关系;无原文返回null"
},
"requiresRecusal" : {
"type" : "string",
"description" : "是否需要回避,只能填是、否或null"
}
},
"required" : [ "department", "hasCompanyRelative", "name", "relationship", "requiresRecusal" ],
"description" : "是否有我司亲属;无原文时可返回null"
},
"contactInfo" : {
"type" : "object",
"properties" : {
"email" : {
"type" : "string",
"description" : "邮箱;无原文返回null"
},
"phone" : {
"type" : "string",
"description" : "手机号;无原文返回null"
},
"postalCode" : {
"type" : "string",
"description" : "邮编;无原文返回null"
},
"residentialAddress" : {
"type" : "string",
"description" : "现居住地址;无原文返回null"
}
},
"required" : [ "email", "phone", "postalCode", "residentialAddress" ],
"description" : "联系信息;无电话邮箱等原文时可返回null"
},
"educations" : {
"description" : "教育经历列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"degree" : {
"type" : "string",
"enum" : [ "小学", "初中", "高中", "中专", "职高", "技校", "高职", "专科", "大专", "本科", "硕士", "硕士研究生", "研究生", "博士", "博士研究生", "博士后" ],
"description" : "标准学历层级;工学、理学、文学、管理学等学位门类不能填入本字段;无法确认时返回null"
},
"endDate" : {
"type" : "string",
"description" : "毕业时间,优先YYYY-MM"
},
"fullGpa" : {
"type" : "string",
"description" : "满分绩点;无原文返回null"
},
"fullTime" : {
"type" : "string",
"description" : "是否全日制,只能填是、否或null,不要输出true或false"
},
"gpa" : {
"type" : "string",
"description" : "绩点;无原文返回null"
},
"gradeRanking" : {
"type" : "string",
"description" : "成绩排名原文值"
},
"hasRetake" : {
"type" : "string",
"description" : "是否有重修/补考,只能填是、否或null,不要输出布尔值"
},
"major" : {
"type" : "string",
"description" : "专业名称原文"
},
"retakeSubjects" : {
"type" : "string",
"description" : "重修/补考科目名称,无内容返回null"
},
"school" : {
"type" : "string",
"description" : "学校名称"
},
"schoolLocation" : {
"type" : "string",
"description" : "院校所在城市、国家或地区"
},
"startDate" : {
"type" : "string",
"description" : "入学时间,优先YYYY-MM"
},
"studyMode" : {
"type" : "string",
"description" : "学习形式,如统招全日制"
}
},
"required" : [ "degree", "endDate", "fullGpa", "fullTime", "gpa", "gradeRanking", "hasRetake", "major", "retakeSubjects", "school", "schoolLocation", "startDate", "studyMode" ],
"description" : "教育经历列表;无则返回空数组"
}
},
"familyInformation" : {
"description" : "家庭成员列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"birthDate" : {
"type" : "string",
"description" : "家庭成员出生日期"
},
"employer" : {
"type" : "string",
"description" : "家庭成员公司或工作单位名称"
},
"name" : {
"type" : "string",
"description" : "家庭成员姓名"
},
"phone" : {
"type" : "string",
"description" : "家庭成员联系电话"
},
"position" : {
"type" : "string",
"description" : "家庭成员职位名称"
},
"relationship" : {
"type" : "string",
"description" : "与本人关系,如父亲、母亲"
}
},
"required" : [ "birthDate", "employer", "name", "phone", "position", "relationship" ],
"description" : "家庭成员列表;无则返回空数组"
}
},
"identityInfo" : {
"type" : "object",
"properties" : {
"documentNumber" : {
"type" : "string",
"description" : "证件号码;无原文返回null"
},
"documentType" : {
"type" : "string",
"description" : "证件类型;无原文返回null"
},
"nationality" : {
"type" : "string",
"description" : "国籍;无原文返回null"
}
},
"required" : [ "documentNumber", "documentType", "nationality" ],
"description" : "证件信息;无原文时可返回null"
},
"jobIntention" : {
"type" : "object",
"properties" : {
"availableDate" : {
"type" : "string",
"description" : "可到岗日期"
},
"currentLocation" : {
"type" : "string",
"description" : "当前所在地或现居住地"
},
"desiredCity" : {
"type" : "string",
"description" : "期望工作地点原文值。必须能在‘期望工作地点/期望工作城市/期望城市/工作地点意向’标签对应的值中找到逐字证据;不得使用或归纳当前所在地、现居住地、户口所在地、籍贯、手机号归属地、学校所在地、应聘单位所在地。只有选项编号且原文没有编号与地点的映射,或标签后未填写文字值时,必须返回null。不得把上海区县归纳改写为上海市"
},
"expectedSalary" : {
"type" : "string",
"description" : "期望薪资原文值"
}
},
"required" : [ "availableDate", "currentLocation", "desiredCity", "expectedSalary" ],
"description" : "求职意向;无原文时可返回null"
},
"languageSkills" : {
"description" : "语言技能列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"certificate" : {
"type" : "string",
"description" : "获得证书,如CET-4、CET-6、IELTS;不同考试分别建记录"
},
"language" : {
"type" : "string",
"description" : "语种,如英语"
},
"proficiency" : {
"type" : "string",
"description" : "掌握程度;无原文返回null"
},
"score" : {
"type" : "string",
"description" : "证书/考试成绩,使用字符串表示;页面无该栏时仍可从原文提取,不得混淆不同考试"
}
},
"required" : [ "certificate", "language", "proficiency", "score" ],
"description" : "语言技能列表;无则返回空数组"
}
},
"lifePhotos" : {
"description" : "生活照附件列表;无则返回空数组",
"type" : "array",
"items" : {
"$ref" : "#/$defs/Attachment",
"description" : "生活照附件列表;无则返回空数组"
}
},
"practiceExperiences" : {
"description" : "实践经历列表;无则返回空数组",
"type" : "array",
"items" : {
"$ref" : "#/$defs/ActivityExperience",
"description" : "实践经历列表;无则返回空数组"
}
},
"professionalSkills" : {
"description" : "专业技能列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"duration" : {
"type" : "string",
"description" : "使用时长;无原文返回null"
},
"proficiency" : {
"type" : "string",
"description" : "掌握程度;无原文返回null"
},
"skillName" : {
"type" : "string",
"description" : "技能名称"
}
},
"required" : [ "duration", "proficiency", "skillName" ],
"description" : "专业技能列表;无则返回空数组"
}
},
"projectExperiences" : {
"description" : "项目经历列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"endDate" : {
"type" : "string",
"description" : "项目结束时间,优先YYYY-MM;仍在进行时返回null"
},
"projectDescription" : {
"type" : "string",
"description" : "项目描述;无原文返回null"
},
"projectName" : {
"type" : "string",
"description" : "项目名称"
},
"responsibilityDescription" : {
"type" : "string",
"description" : "本人职责描述;无原文返回null"
},
"startDate" : {
"type" : "string",
"description" : "项目开始时间,优先YYYY-MM"
}
},
"required" : [ "endDate", "projectDescription", "projectName", "responsibilityDescription", "startDate" ],
"description" : "项目经历列表;无则返回空数组"
}
},
"selfEvaluation" : {
"type" : "string",
"description" : "自我评价;无原文返回null"
},
"specialtiesAndInterests" : {
"type" : "string",
"description" : "特长兴趣;无原文返回null"
},
"trainingExperiences" : {
"description" : "培训经历列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"course" : {
"type" : "string",
"description" : "培训课程名称;无原文返回null"
},
"description" : {
"type" : "string",
"description" : "培训内容描述;无原文返回null"
},
"endDate" : {
"type" : "string",
"description" : "培训结束时间,优先YYYY-MM;仍在进行时返回null"
},
"institution" : {
"type" : "string",
"description" : "培训机构名称"
},
"startDate" : {
"type" : "string",
"description" : "培训开始时间,优先YYYY-MM"
}
},
"required" : [ "course", "description", "endDate", "institution", "startDate" ],
"description" : "培训经历列表;无则返回空数组"
}
},
"workExperiences" : {
"description" : "工作/实习经历列表;无则返回空数组",
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"achievements" : {
"type" : "string",
"description" : "明确记载的工作业绩或成果,不与工作内容重复扩写"
},
"company" : {
"type" : "string",
"description" : "公司、学校或实习单位的完整原文名称,必须逐字提取,禁止概括、改写、匿名化或使用“某公司、科技企业”等泛化名称;原文未提供单位名称时返回null"
},
"department" : {
"type" : "string",
"description" : "所在部门"
},
"endDate" : {
"type" : "string",
"description" : "工作或实习结束时间,仍在进行时返回null"
},
"experienceType" : {
"type" : "string",
"description" : "经历类型,只能根据原文区分正式工作或实习"
},
"leavingReason" : {
"type" : "string",
"description" : "离职原因原文值"
},
"position" : {
"type" : "string",
"description" : "职位名称"
},
"startDate" : {
"type" : "string",
"description" : "工作或实习开始时间,优先YYYY-MM"
},
"workDescription" : {
"type" : "string",
"description" : "工作描述;多条事项使用换行,不得生成无意义横线、不得截断或编造"
}
},
"required" : [ "achievements", "company", "department", "endDate", "experienceType", "leavingReason", "position", "startDate", "workDescription" ],
"description" : "工作/实习经历列表;无则返回空数组"
}
}
},
"required" : [ "additionalQuestions", "attachments", "awards", "basicInfo", "campusActivities", "certificates", "companyRelative", "contactInfo", "educations", "familyInformation", "identityInfo", "jobIntention", "languageSkills", "lifePhotos", "practiceExperiences", "professionalSkills", "projectExperiences", "selfEvaluation", "specialtiesAndInterests", "trainingExperiences", "workExperiences" ]
}
},
"required" : [ "response" ]
}
实际输出
当前代码的返回结果(40 条 message 完全相同,无任何字段信息):
已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string; 已找到 null,必须是 string
期望输出
每条错误都应带上字段的 JSON Pointer 路径(/ 分隔),有利于大模型根据错误修正json内容,也有利于人工定位问题:
/response/additionalQuestions/majorDiseaseOrFamilyGeneticHistory: 已找到 null,必须是 string
/response/additionalQuestions/majorViolationsOrCriminalInvolvement: 已找到 null,必须是 string
/response/awards/0/awardLevel: 已找到 null,必须是 string
/response/awards/0/awardingOrganization: 已找到 null,必须是 string
/response/awards/0/certifier: 已找到 null,必须是 string
/response/awards/0/obtainedDate: 已找到 null,必须是 string
/response/awards/1/awardLevel: 已找到 null,必须是 string
/response/awards/1/awardingOrganization: 已找到 null,必须是 string
/response/awards/1/certifier: 已找到 null,必须是 string
/response/awards/1/obtainedDate: 已找到 null,必须是 string
/response/awards/2/awardLevel: 已找到 null,必须是 string
/response/awards/2/awardingOrganization: 已找到 null,必须是 string
/response/awards/2/certifier: 已找到 null,必须是 string
/response/awards/2/obtainedDate: 已找到 null,必须是 string
/response/awards/3/awardLevel: 已找到 null,必须是 string
/response/awards/3/awardingOrganization: 已找到 null,必须是 string
/response/awards/3/certifier: 已找到 null,必须是 string
/response/awards/3/obtainedDate: 已找到 null,必须是 string
/response/awards/4/awardLevel: 已找到 null,必须是 string
/response/awards/4/awardingOrganization: 已找到 null,必须是 string
/response/awards/4/certifier: 已找到 null,必须是 string
/response/awards/4/obtainedDate: 已找到 null,必须是 string
/response/basicInfo/employmentStatus: 已找到 null,必须是 string
/response/basicInfo/overseasEducation: 已找到 null,必须是 string
/response/basicInfo/preEnrollmentHouseholdLocation: 已找到 null,必须是 string
/response/basicInfo/preEnrollmentHouseholdType: 已找到 null,必须是 string
/response/basicInfo/workYears: 已找到 null,必须是 string
/response/companyRelative/department: 已找到 null,必须是 string
/response/companyRelative/name: 已找到 null,必须是 string
/response/companyRelative/relationship: 已找到 null,必须是 string
/response/companyRelative/requiresRecusal: 已找到 null,必须是 string
/response/contactInfo/postalCode: 已找到 null,必须是 string
/response/educations/0/hasRetake: 已找到 null,必须是 string
/response/educations/0/retakeSubjects: 已找到 null,必须是 string
/response/educations/1/hasRetake: 已找到 null,必须是 string
/response/educations/1/retakeSubjects: 已找到 null,必须是 string
/response/jobIntention/availableDate: 已找到 null,必须是 string
/response/jobIntention/expectedSalary: 已找到 null,必须是 string
/response/selfEvaluation: 已找到 null,必须是 string
/response/specialtiesAndInterests: 已找到 null,必须是 string
修复建议
在拼装错误信息时,把 Error.getInstanceLocation()(字段的 JSON 路径)一并输出。注意 NodePath.toString() 默认返回 JSON Path 形式($.response.awards[0].awardLevel),如需上述 JSON Pointer 形式(/response/awards/0/awardLevel),可借助 com.networknt.schema.path.PathType.JSON_POINTER / convertToJsonPointer 转换后拼接。
例如(示意,具体实现以代码为准):
return errors.stream()
.map(e -> e.getInstanceLocation() + ": " + e.getMessage())
.collect(Collectors.joining("; "));
同时为 validateInput 补充单元测试:用上述 content/schema 作为 fixture,断言返回的错误信息包含字段路径(如 /response/basicInfo/name)。
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(core): include field path in tool validation error messages (#2718)