{"record":{"id":"d89cb6b20c2c74a3","repo":"microsoft/autogen","slug":"top-must-be-a-positive-integer","errorCode":null,"errorMessage":"top must be a positive integer","messagePattern":"top must be a positive integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/tools/azure/_config.py","lineNumber":166,"sourceCode":"            raise ValueError(\"endpoint must be a valid URL starting with http:// or https://\")\n        return v\n\n    @field_validator(\"query_type\")\n    def normalize_query_type(cls, v: QueryTypeLiteral) -> QueryTypeLiteral:\n        \"\"\"Normalize query type to standard values.\"\"\"\n        if not v:\n            return \"simple\"\n\n        if isinstance(v, str) and v.lower() == \"fulltext\":\n            return \"full\"\n\n        return v\n\n    @field_validator(\"top\")\n    def validate_top(cls, v: Optional[int]) -> Optional[int]:\n        \"\"\"Ensure top is a positive integer if provided.\"\"\"\n        if v is not None and v <= 0:\n            raise ValueError(\"top must be a positive integer\")\n        return v\n\n    @model_validator(mode=\"after\")\n    def validate_interdependent_fields(self) -> \"AzureAISearchConfig\":\n        \"\"\"Validate interdependent fields after all fields have been parsed.\"\"\"\n        if self.query_type == \"semantic\" and not self.semantic_config_name:\n            raise ValueError(\"semantic_config_name must be provided when query_type is 'semantic'\")\n\n        if self.query_type == \"vector\" and not self.vector_fields:\n            raise ValueError(\"vector_fields must be provided for vector search\")\n\n        if (\n            self.embedding_provider\n            and self.embedding_provider.lower() == \"azure_openai\"\n            and self.embedding_model\n            and not self.openai_endpoint\n        ):\n            raise ValueError(\"openai_endpoint must be provided for azure_openai embedding provider\")","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/tools/azure/_config.py#L148-L184","documentation":"The pydantic field validator for top rejects non-positive values: top must be a positive integer when provided (None is allowed and means the service default). top maps to the $top search parameter controlling how many results are returned.","triggerScenarios":"Passing top=0 or a negative number to any Azure AI Search tool factory or to AzureAISearchConfig directly; computing top dynamically (e.g. top=limit - requested) where the arithmetic can reach 0.","commonSituations":"top derived from user input or pagination math that underflows to 0; copying a config where top was decremented; treating 0 as 'no limit' (the API treats None/omission as the default, not 0).","solutions":["Pass top>=1, e.g. top=5.","Use top=None (or omit it) for the service default number of results.","Clamp dynamic values: top=max(1, computed_top)."],"exampleFix":"# before\ntool = AzureAISearchTool(name='s', endpoint=ep, index_name='idx', credential=cred, top=max(0, user_limit - page))\n# after\ntool = AzureAISearchTool(name='s', endpoint=ep, index_name='idx', credential=cred, top=max(1, user_limit - page))","handlingStrategy":"validation","validationCode":"def top_is_valid(top) -> bool:\n    return top is None or (isinstance(top, int) and not isinstance(top, bool) and top >= 1)","typeGuard":"def is_positive_top(top) -> bool:\n    return top is None or (isinstance(top, int) and top > 0)","tryCatchPattern":null,"preventionTips":["Clamp computed values: top = max(1, computed) or pass None for the service default.","Remember 0 is not 'unlimited' — omit top or use None for the default result count.","Validate top in config schemas with minimum: 1."],"tags":["azure","azure-ai-search","configuration","validation","pydantic"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}