Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

validation_utils.py 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from collections import Counter
  17. from enum import auto
  18. from typing import Annotated, Any
  19. from uuid import UUID
  20. from flask import Request
  21. from pydantic import BaseModel, Field, StringConstraints, ValidationError, field_validator
  22. from pydantic_core import PydanticCustomError
  23. from strenum import StrEnum
  24. from werkzeug.exceptions import BadRequest, UnsupportedMediaType
  25. from api.constants import DATASET_NAME_LIMIT
  26. def validate_and_parse_json_request(request: Request, validator: type[BaseModel], *, extras: dict[str, Any] | None = None, exclude_unset: bool = False) -> tuple[dict[str, Any] | None, str | None]:
  27. """
  28. Validates and parses JSON requests through a multi-stage validation pipeline.
  29. Implements a four-stage validation process:
  30. 1. Content-Type verification (must be application/json)
  31. 2. JSON syntax validation
  32. 3. Payload structure type checking
  33. 4. Pydantic model validation with error formatting
  34. Args:
  35. request (Request): Flask request object containing HTTP payload
  36. validator (type[BaseModel]): Pydantic model class for data validation
  37. extras (dict[str, Any] | None): Additional fields to merge into payload
  38. before validation. These fields will be removed from the final output
  39. exclude_unset (bool): Whether to exclude fields that have not been explicitly set
  40. Returns:
  41. tuple[Dict[str, Any] | None, str | None]:
  42. - First element:
  43. - Validated dictionary on success
  44. - None on validation failure
  45. - Second element:
  46. - None on success
  47. - Diagnostic error message on failure
  48. Raises:
  49. UnsupportedMediaType: When Content-Type header is not application/json
  50. BadRequest: For structural JSON syntax errors
  51. ValidationError: When payload violates Pydantic schema rules
  52. Examples:
  53. >>> validate_and_parse_json_request(valid_request, DatasetSchema)
  54. ({"name": "Dataset1", "format": "csv"}, None)
  55. >>> validate_and_parse_json_request(xml_request, DatasetSchema)
  56. (None, "Unsupported content type: Expected application/json, got text/xml")
  57. >>> validate_and_parse_json_request(bad_json_request, DatasetSchema)
  58. (None, "Malformed JSON syntax: Missing commas/brackets or invalid encoding")
  59. Notes:
  60. 1. Validation Priority:
  61. - Content-Type verification precedes JSON parsing
  62. - Structural validation occurs before schema validation
  63. 2. Extra fields added via `extras` parameter are automatically removed
  64. from the final output after validation
  65. """
  66. try:
  67. payload = request.get_json() or {}
  68. except UnsupportedMediaType:
  69. return None, f"Unsupported content type: Expected application/json, got {request.content_type}"
  70. except BadRequest:
  71. return None, "Malformed JSON syntax: Missing commas/brackets or invalid encoding"
  72. if not isinstance(payload, dict):
  73. return None, f"Invalid request payload: expected object, got {type(payload).__name__}"
  74. try:
  75. if extras is not None:
  76. payload.update(extras)
  77. validated_request = validator(**payload)
  78. except ValidationError as e:
  79. return None, format_validation_error_message(e)
  80. parsed_payload = validated_request.model_dump(by_alias=True, exclude_unset=exclude_unset)
  81. if extras is not None:
  82. for key in list(parsed_payload.keys()):
  83. if key in extras:
  84. del parsed_payload[key]
  85. return parsed_payload, None
  86. def validate_and_parse_request_args(request: Request, validator: type[BaseModel], *, extras: dict[str, Any] | None = None) -> tuple[dict[str, Any] | None, str | None]:
  87. """
  88. Validates and parses request arguments against a Pydantic model.
  89. This function performs a complete request validation workflow:
  90. 1. Extracts query parameters from the request
  91. 2. Merges with optional extra values (if provided)
  92. 3. Validates against the specified Pydantic model
  93. 4. Cleans the output by removing extra values
  94. 5. Returns either parsed data or an error message
  95. Args:
  96. request (Request): Web framework request object containing query parameters
  97. validator (type[BaseModel]): Pydantic model class for validation
  98. extras (dict[str, Any] | None): Optional additional values to include in validation
  99. but exclude from final output. Defaults to None.
  100. Returns:
  101. tuple[dict[str, Any] | None, str | None]:
  102. - First element: Validated/parsed arguments as dict if successful, None otherwise
  103. - Second element: Formatted error message if validation failed, None otherwise
  104. Behavior:
  105. - Query parameters are merged with extras before validation
  106. - Extras are automatically removed from the final output
  107. - All validation errors are formatted into a human-readable string
  108. Raises:
  109. TypeError: If validator is not a Pydantic BaseModel subclass
  110. Examples:
  111. Successful validation:
  112. >>> validate_and_parse_request_args(request, MyValidator)
  113. ({'param1': 'value'}, None)
  114. Failed validation:
  115. >>> validate_and_parse_request_args(request, MyValidator)
  116. (None, "param1: Field required")
  117. With extras:
  118. >>> validate_and_parse_request_args(request, MyValidator, extras={'internal_id': 123})
  119. ({'param1': 'value'}, None) # internal_id removed from output
  120. Notes:
  121. - Uses request.args.to_dict() for Flask-compatible parameter extraction
  122. - Maintains immutability of original request arguments
  123. - Preserves type conversion from Pydantic validation
  124. """
  125. args = request.args.to_dict(flat=True)
  126. try:
  127. if extras is not None:
  128. args.update(extras)
  129. validated_args = validator(**args)
  130. except ValidationError as e:
  131. return None, format_validation_error_message(e)
  132. parsed_args = validated_args.model_dump()
  133. if extras is not None:
  134. for key in list(parsed_args.keys()):
  135. if key in extras:
  136. del parsed_args[key]
  137. return parsed_args, None
  138. def format_validation_error_message(e: ValidationError) -> str:
  139. """
  140. Formats validation errors into a standardized string format.
  141. Processes pydantic ValidationError objects to create human-readable error messages
  142. containing field locations, error descriptions, and input values.
  143. Args:
  144. e (ValidationError): The validation error instance containing error details
  145. Returns:
  146. str: Formatted error messages joined by newlines. Each line contains:
  147. - Field path (dot-separated)
  148. - Error message
  149. - Truncated input value (max 128 chars)
  150. Example:
  151. >>> try:
  152. ... UserModel(name=123, email="invalid")
  153. ... except ValidationError as e:
  154. ... print(format_validation_error_message(e))
  155. Field: <name> - Message: <Input should be a valid string> - Value: <123>
  156. Field: <email> - Message: <value is not a valid email address> - Value: <invalid>
  157. """
  158. error_messages = []
  159. for error in e.errors():
  160. field = ".".join(map(str, error["loc"]))
  161. msg = error["msg"]
  162. input_val = error["input"]
  163. input_str = str(input_val)
  164. if len(input_str) > 128:
  165. input_str = input_str[:125] + "..."
  166. error_msg = f"Field: <{field}> - Message: <{msg}> - Value: <{input_str}>"
  167. error_messages.append(error_msg)
  168. return "\n".join(error_messages)
  169. def normalize_str(v: Any) -> Any:
  170. """
  171. Normalizes string values to a standard format while preserving non-string inputs.
  172. Performs the following transformations when input is a string:
  173. 1. Trims leading/trailing whitespace (str.strip())
  174. 2. Converts to lowercase (str.lower())
  175. Non-string inputs are returned unchanged, making this function safe for mixed-type
  176. processing pipelines.
  177. Args:
  178. v (Any): Input value to normalize. Accepts any Python object.
  179. Returns:
  180. Any: Normalized string if input was string-type, original value otherwise.
  181. Behavior Examples:
  182. String Input: " Admin " → "admin"
  183. Empty String: " " → "" (empty string)
  184. Non-String:
  185. - 123 → 123
  186. - None → None
  187. - ["User"] → ["User"]
  188. Typical Use Cases:
  189. - Standardizing user input
  190. - Preparing data for case-insensitive comparison
  191. - Cleaning API parameters
  192. - Normalizing configuration values
  193. Edge Cases:
  194. - Unicode whitespace is handled by str.strip()
  195. - Locale-independent lowercasing (str.lower())
  196. - Preserves falsy values (0, False, etc.)
  197. Example:
  198. >>> normalize_str(" ReadOnly ")
  199. 'readonly'
  200. >>> normalize_str(42)
  201. 42
  202. """
  203. if isinstance(v, str):
  204. stripped = v.strip()
  205. normalized = stripped.lower()
  206. return normalized
  207. return v
  208. def validate_uuid1_hex(v: Any) -> str:
  209. """
  210. Validates and converts input to a UUID version 1 hexadecimal string.
  211. This function performs strict validation and normalization:
  212. 1. Accepts either UUID objects or UUID-formatted strings
  213. 2. Verifies the UUID is version 1 (time-based)
  214. 3. Returns the 32-character hexadecimal representation
  215. Args:
  216. v (Any): Input value to validate. Can be:
  217. - UUID object (must be version 1)
  218. - String in UUID format (e.g. "550e8400-e29b-41d4-a716-446655440000")
  219. Returns:
  220. str: 32-character lowercase hexadecimal string without hyphens
  221. Example: "550e8400e29b41d4a716446655440000"
  222. Raises:
  223. PydanticCustomError: With code "invalid_UUID1_format" when:
  224. - Input is not a UUID object or valid UUID string
  225. - UUID version is not 1
  226. - String doesn't match UUID format
  227. Examples:
  228. Valid cases:
  229. >>> validate_uuid1_hex("550e8400-e29b-41d4-a716-446655440000")
  230. '550e8400e29b41d4a716446655440000'
  231. >>> validate_uuid1_hex(UUID('550e8400-e29b-41d4-a716-446655440000'))
  232. '550e8400e29b41d4a716446655440000'
  233. Invalid cases:
  234. >>> validate_uuid1_hex("not-a-uuid") # raises PydanticCustomError
  235. >>> validate_uuid1_hex(12345) # raises PydanticCustomError
  236. >>> validate_uuid1_hex(UUID(int=0)) # v4, raises PydanticCustomError
  237. Notes:
  238. - Uses Python's built-in UUID parser for format validation
  239. - Version check prevents accidental use of other UUID versions
  240. - Hyphens in input strings are automatically removed in output
  241. """
  242. try:
  243. uuid_obj = UUID(v) if isinstance(v, str) else v
  244. if uuid_obj.version != 1:
  245. raise PydanticCustomError("invalid_UUID1_format", "Must be a UUID1 format")
  246. return uuid_obj.hex
  247. except (AttributeError, ValueError, TypeError):
  248. raise PydanticCustomError("invalid_UUID1_format", "Invalid UUID1 format")
  249. class PermissionEnum(StrEnum):
  250. me = auto()
  251. team = auto()
  252. class ChunkMethodEnum(StrEnum):
  253. naive = auto()
  254. book = auto()
  255. email = auto()
  256. laws = auto()
  257. manual = auto()
  258. one = auto()
  259. paper = auto()
  260. picture = auto()
  261. presentation = auto()
  262. qa = auto()
  263. table = auto()
  264. tag = auto()
  265. class GraphragMethodEnum(StrEnum):
  266. light = auto()
  267. general = auto()
  268. class Base(BaseModel):
  269. class Config:
  270. extra = "forbid"
  271. class RaptorConfig(Base):
  272. use_raptor: bool = Field(default=False)
  273. prompt: Annotated[
  274. str,
  275. StringConstraints(strip_whitespace=True, min_length=1),
  276. Field(
  277. default="Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:\n {cluster_content}\nThe above is the content you need to summarize."
  278. ),
  279. ]
  280. max_token: int = Field(default=256, ge=1, le=2048)
  281. threshold: float = Field(default=0.1, ge=0.0, le=1.0)
  282. max_cluster: int = Field(default=64, ge=1, le=1024)
  283. random_seed: int = Field(default=0, ge=0)
  284. class GraphragConfig(Base):
  285. use_graphrag: bool = Field(default=False)
  286. entity_types: list[str] = Field(default_factory=lambda: ["organization", "person", "geo", "event", "category"])
  287. method: GraphragMethodEnum = Field(default=GraphragMethodEnum.light)
  288. community: bool = Field(default=False)
  289. resolution: bool = Field(default=False)
  290. class ParserConfig(Base):
  291. auto_keywords: int = Field(default=0, ge=0, le=32)
  292. auto_questions: int = Field(default=0, ge=0, le=10)
  293. chunk_token_num: int = Field(default=512, ge=1, le=2048)
  294. delimiter: str = Field(default=r"\n", min_length=1)
  295. graphrag: GraphragConfig | None = None
  296. html4excel: bool = False
  297. layout_recognize: str = "DeepDOC"
  298. raptor: RaptorConfig | None = None
  299. tag_kb_ids: list[str] = Field(default_factory=list)
  300. topn_tags: int = Field(default=1, ge=1, le=10)
  301. filename_embd_weight: float | None = Field(default=0.1, ge=0.0, le=1.0)
  302. task_page_size: int | None = Field(default=None, ge=1)
  303. pages: list[list[int]] | None = None
  304. class CreateDatasetReq(Base):
  305. name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=DATASET_NAME_LIMIT), Field(...)]
  306. avatar: str | None = Field(default=None, max_length=65535)
  307. description: str | None = Field(default=None, max_length=65535)
  308. embedding_model: str | None = Field(default=None, max_length=255, serialization_alias="embd_id")
  309. permission: PermissionEnum = Field(default=PermissionEnum.me, min_length=1, max_length=16)
  310. chunk_method: ChunkMethodEnum = Field(default=ChunkMethodEnum.naive, min_length=1, max_length=32, serialization_alias="parser_id")
  311. parser_config: ParserConfig | None = Field(default=None)
  312. @field_validator("avatar")
  313. @classmethod
  314. def validate_avatar_base64(cls, v: str | None) -> str | None:
  315. """
  316. Validates Base64-encoded avatar string format and MIME type compliance.
  317. Implements a three-stage validation workflow:
  318. 1. MIME prefix existence check
  319. 2. MIME type format validation
  320. 3. Supported type verification
  321. Args:
  322. v (str): Raw avatar field value
  323. Returns:
  324. str: Validated Base64 string
  325. Raises:
  326. PydanticCustomError: For structural errors in these cases:
  327. - Missing MIME prefix header
  328. - Invalid MIME prefix format
  329. - Unsupported image MIME type
  330. Example:
  331. ```python
  332. # Valid case
  333. CreateDatasetReq(avatar="data:image/png;base64,iVBORw0KGg...")
  334. # Invalid cases
  335. CreateDatasetReq(avatar="image/jpeg;base64,...") # Missing 'data:' prefix
  336. CreateDatasetReq(avatar="data:video/mp4;base64,...") # Unsupported MIME type
  337. ```
  338. """
  339. if v is None:
  340. return v
  341. if "," in v:
  342. prefix, _ = v.split(",", 1)
  343. if not prefix.startswith("data:"):
  344. raise PydanticCustomError("format_invalid", "Invalid MIME prefix format. Must start with 'data:'")
  345. mime_type = prefix[5:].split(";")[0]
  346. supported_mime_types = ["image/jpeg", "image/png"]
  347. if mime_type not in supported_mime_types:
  348. raise PydanticCustomError("format_invalid", "Unsupported MIME type. Allowed: {supported_mime_types}", {"supported_mime_types": supported_mime_types})
  349. return v
  350. else:
  351. raise PydanticCustomError("format_invalid", "Missing MIME prefix. Expected format: data:<mime>;base64,<data>")
  352. @field_validator("embedding_model", mode="before")
  353. @classmethod
  354. def normalize_embedding_model(cls, v: Any) -> Any:
  355. if isinstance(v, str):
  356. return v.strip()
  357. return v
  358. @field_validator("embedding_model", mode="after")
  359. @classmethod
  360. def validate_embedding_model(cls, v: str | None) -> str | None:
  361. """
  362. Validates embedding model identifier format compliance.
  363. Validation pipeline:
  364. 1. Structural format verification
  365. 2. Component non-empty check
  366. 3. Value normalization
  367. Args:
  368. v (str): Raw model identifier
  369. Returns:
  370. str: Validated <model_name>@<provider> format
  371. Raises:
  372. PydanticCustomError: For these violations:
  373. - Missing @ separator
  374. - Empty model_name/provider
  375. - Invalid component structure
  376. Examples:
  377. Valid: "text-embedding-3-large@openai"
  378. Invalid: "invalid_model" (no @)
  379. Invalid: "@openai" (empty model_name)
  380. Invalid: "text-embedding-3-large@" (empty provider)
  381. """
  382. if isinstance(v, str):
  383. if "@" not in v:
  384. raise PydanticCustomError("format_invalid", "Embedding model identifier must follow <model_name>@<provider> format")
  385. components = v.split("@", 1)
  386. if len(components) != 2 or not all(components):
  387. raise PydanticCustomError("format_invalid", "Both model_name and provider must be non-empty strings")
  388. model_name, provider = components
  389. if not model_name.strip() or not provider.strip():
  390. raise PydanticCustomError("format_invalid", "Model name and provider cannot be whitespace-only strings")
  391. return v
  392. @field_validator("permission", mode="before")
  393. @classmethod
  394. def normalize_permission(cls, v: Any) -> Any:
  395. return normalize_str(v)
  396. @field_validator("parser_config", mode="before")
  397. @classmethod
  398. def normalize_empty_parser_config(cls, v: Any) -> Any:
  399. """
  400. Normalizes empty parser configuration by converting empty dictionaries to None.
  401. This validator ensures consistent handling of empty parser configurations across
  402. the application by converting empty dicts to None values.
  403. Args:
  404. v (Any): Raw input value for the parser config field
  405. Returns:
  406. Any: Returns None if input is an empty dict, otherwise returns the original value
  407. Example:
  408. >>> normalize_empty_parser_config({})
  409. None
  410. >>> normalize_empty_parser_config({"key": "value"})
  411. {"key": "value"}
  412. """
  413. if v == {}:
  414. return None
  415. return v
  416. @field_validator("parser_config", mode="after")
  417. @classmethod
  418. def validate_parser_config_json_length(cls, v: ParserConfig | None) -> ParserConfig | None:
  419. """
  420. Validates serialized JSON length constraints for parser configuration.
  421. Implements a two-stage validation workflow:
  422. 1. Null check - bypass validation for empty configurations
  423. 2. Model serialization - convert Pydantic model to JSON string
  424. 3. Size verification - enforce maximum allowed payload size
  425. Args:
  426. v (ParserConfig | None): Raw parser configuration object
  427. Returns:
  428. ParserConfig | None: Validated configuration object
  429. Raises:
  430. PydanticCustomError: When serialized JSON exceeds 65,535 characters
  431. """
  432. if v is None:
  433. return None
  434. if (json_str := v.model_dump_json()) and len(json_str) > 65535:
  435. raise PydanticCustomError("string_too_long", "Parser config exceeds size limit (max 65,535 characters). Current size: {actual}", {"actual": len(json_str)})
  436. return v
  437. class UpdateDatasetReq(CreateDatasetReq):
  438. dataset_id: str = Field(...)
  439. name: Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=DATASET_NAME_LIMIT), Field(default="")]
  440. pagerank: int = Field(default=0, ge=0, le=100)
  441. @field_validator("dataset_id", mode="before")
  442. @classmethod
  443. def validate_dataset_id(cls, v: Any) -> str:
  444. return validate_uuid1_hex(v)
  445. class DeleteReq(Base):
  446. ids: list[str] | None = Field(...)
  447. @field_validator("ids", mode="after")
  448. @classmethod
  449. def validate_ids(cls, v_list: list[str] | None) -> list[str] | None:
  450. """
  451. Validates and normalizes a list of UUID strings with None handling.
  452. This post-processing validator performs:
  453. 1. None input handling (pass-through)
  454. 2. UUID version 1 validation for each list item
  455. 3. Duplicate value detection
  456. 4. Returns normalized UUID hex strings or None
  457. Args:
  458. v_list (list[str] | None): Input list that has passed initial validation.
  459. Either a list of UUID strings or None.
  460. Returns:
  461. list[str] | None:
  462. - None if input was None
  463. - List of normalized UUID hex strings otherwise:
  464. * 32-character lowercase
  465. * Valid UUID version 1
  466. * Unique within list
  467. Raises:
  468. PydanticCustomError: With structured error details when:
  469. - "invalid_UUID1_format": Any string fails UUIDv1 validation
  470. - "duplicate_uuids": If duplicate IDs are detected
  471. Validation Rules:
  472. - None input returns None
  473. - Empty list returns empty list
  474. - All non-None items must be valid UUIDv1
  475. - No duplicates permitted
  476. - Original order preserved
  477. Examples:
  478. Valid cases:
  479. >>> validate_ids(None)
  480. None
  481. >>> validate_ids([])
  482. []
  483. >>> validate_ids(["550e8400-e29b-41d4-a716-446655440000"])
  484. ["550e8400e29b41d4a716446655440000"]
  485. Invalid cases:
  486. >>> validate_ids(["invalid"])
  487. # raises PydanticCustomError(invalid_UUID1_format)
  488. >>> validate_ids(["550e...", "550e..."])
  489. # raises PydanticCustomError(duplicate_uuids)
  490. Security Notes:
  491. - Validates UUID version to prevent version spoofing
  492. - Duplicate check prevents data injection
  493. - None handling maintains pipeline integrity
  494. """
  495. if v_list is None:
  496. return None
  497. ids_list = []
  498. for v in v_list:
  499. try:
  500. ids_list.append(validate_uuid1_hex(v))
  501. except PydanticCustomError as e:
  502. raise e
  503. duplicates = [item for item, count in Counter(ids_list).items() if count > 1]
  504. if duplicates:
  505. duplicates_str = ", ".join(duplicates)
  506. raise PydanticCustomError("duplicate_uuids", "Duplicate ids: '{duplicate_ids}'", {"duplicate_ids": duplicates_str})
  507. return ids_list
  508. class DeleteDatasetReq(DeleteReq): ...
  509. class OrderByEnum(StrEnum):
  510. create_time = auto()
  511. update_time = auto()
  512. class BaseListReq(Base):
  513. id: str | None = None
  514. name: str | None = None
  515. page: int = Field(default=1, ge=1)
  516. page_size: int = Field(default=30, ge=1)
  517. orderby: OrderByEnum = Field(default=OrderByEnum.create_time)
  518. desc: bool = Field(default=True)
  519. @field_validator("id", mode="before")
  520. @classmethod
  521. def validate_id(cls, v: Any) -> str:
  522. return validate_uuid1_hex(v)
  523. @field_validator("orderby", mode="before")
  524. @classmethod
  525. def normalize_orderby(cls, v: Any) -> Any:
  526. return normalize_str(v)
  527. class ListDatasetReq(BaseListReq): ...