{"record":{"id":"d518494525ffc6db","repo":"PaddlePaddle/PaddleOCR","slug":"top-p-must-be-greater-than-0-and-less-than-or-equa","errorCode":null,"errorMessage":"top_p must be greater than 0 and less than or equal to 1.","messagePattern":"top_p must be greater than 0 and less than or equal to 1\\.","errorType":"validation","errorClass":"InvalidRequestError","httpStatus":null,"severity":"error","filePath":"paddleocr/_api_client/models.py","lineNumber":186,"sourceCode":"DocParsingOptions = Union[PPStructureV3Options, PaddleOCRVLOptions]\n\n\ndef _build_payload(options) -> dict:\n    payload = {}\n    for field in fields(options):\n        value = getattr(options, field.name)\n        if value is None:\n            continue\n        if field.name == \"extra_options\":\n            payload.update(value)\n        else:\n            payload[snake_to_camel(field.name)] = value\n    return payload\n\n\ndef _validate_vl_options(options: PaddleOCRVLOptions) -> None:\n    if options.top_p is not None and not (0 < options.top_p <= 1):\n        raise InvalidRequestError(\n            \"top_p must be greater than 0 and less than or equal to 1.\"\n        )\n    if options.temperature is not None and options.temperature < 0:\n        raise InvalidRequestError(\"temperature must be greater than or equal to 0.\")\n    if options.repetition_penalty is not None and options.repetition_penalty <= 0:\n        raise InvalidRequestError(\"repetition_penalty must be greater than 0.\")\n    if options.min_pixels is not None and options.min_pixels <= 0:\n        raise InvalidRequestError(\"min_pixels must be greater than 0.\")\n    if options.max_pixels is not None and options.max_pixels <= 0:\n        raise InvalidRequestError(\"max_pixels must be greater than 0.\")\n    if (\n        options.min_pixels is not None\n        and options.max_pixels is not None\n        and options.min_pixels > options.max_pixels\n    ):\n        raise InvalidRequestError(\"min_pixels cannot be greater than max_pixels.\")\n","sourceCodeStart":168,"sourceCodeEnd":203,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr/_api_client/models.py#L168-L203","documentation":"InvalidRequestError thrown by _validate_vl_options when PaddleOCRVLOptions.top_p is set outside the range (0, 1]. top_p is nucleus-sampling probability; zero or negative values, and values above 1, are meaningless and rejected client-side before the request is sent.","triggerScenarios":"Passing PaddleOCRVLOptions(top_p=0), top_p=1.2, or top_p=-0.1 to a VL (vision-language) API call; misreading top_p as a percentage (e.g. 50 for 50%).","commonSituations":"Porting hyperparameters from another SDK where top_p is a 0-100 percent; copy-pasting sampling configs tuned for temperature-style parameters.","solutions":["Set top_p to a float in (0, 1], e.g. 0.9","Leave top_p=None to use the server default","If you meant a percentage, divide by 100 first"],"exampleFix":"# before\noptions = PaddleOCRVLOptions(top_p=90)\n# after\noptions = PaddleOCRVLOptions(top_p=0.9)","handlingStrategy":"validation","validationCode":"def valid_top_p(v):\n    return v is None or (isinstance(v, (int, float)) and 0 < v <= 1)\n\nassert valid_top_p(options.top_p), f'bad top_p={options.top_p}'","typeGuard":null,"tryCatchPattern":"from paddleocr._api_client.errors import InvalidRequestError\n\ntry:\n    client.predict(..., vl_options=options)\nexcept InvalidRequestError as e:\n    if 'top_p' in str(e):\n        options.top_p = min(max(options.top_p, 1e-6), 1.0)\n    else:\n        raise","preventionTips":["Remember top_p is a 0-1 fraction, not a percentage","Centralize sampling config in one validated helper"],"tags":["validation","api-client","sampling"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}