{"record":{"id":"60c2a74fddef254b","repo":"huggingface/smolagents","slug":"invalid-extract-format-choose-between-wiki-or","errorCode":null,"errorMessage":"Invalid extract_format. Choose between 'WIKI' or 'HTML'.","messagePattern":"Invalid extract_format\\. Choose between 'WIKI' or 'HTML'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/default_tools.py","lineNumber":615,"sourceCode":"        except ImportError as e:\n            raise ImportError(\n                \"You must install `wikipedia-api` to run this tool: for instance run `pip install wikipedia-api`\"\n            ) from e\n        if not user_agent:\n            raise ValueError(\"User-agent is required. Provide a meaningful identifier for your project.\")\n\n        self.user_agent = user_agent\n        self.language = language\n        self.content_type = content_type\n\n        # Map string format to wikipediaapi.ExtractFormat\n        extract_format_map = {\n            \"WIKI\": wikipediaapi.ExtractFormat.WIKI,\n            \"HTML\": wikipediaapi.ExtractFormat.HTML,\n        }\n\n        if extract_format not in extract_format_map:\n            raise ValueError(\"Invalid extract_format. Choose between 'WIKI' or 'HTML'.\")\n\n        self.extract_format = extract_format_map[extract_format]\n\n        self.wiki = wikipediaapi.Wikipedia(\n            user_agent=self.user_agent, language=self.language, extract_format=self.extract_format\n        )\n\n    def forward(self, query: str) -> str:\n        try:\n            page = self.wiki.page(query)\n\n            if not page.exists():\n                return f\"No Wikipedia page found for '{query}'. Try a different query.\"\n\n            title = page.title\n            url = page.fullurl\n\n            if self.content_type == \"summary\":","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/default_tools.py#L597-L633","documentation":"Raised by WikipediaSearchTool.__init__ when extract_format is not 'WIKI' or 'HTML'. These two strings map to wikipediaapi.ExtractFormat members; any other value (including lowercase variants) is rejected before the Wikipedia client is built.","triggerScenarios":"Passing extract_format='wiki' (lowercase), 'markdown', 'TEXT', or any other string to the constructor.","commonSituations":"Assuming case-insensitive values or other formats like markdown/plain text; passing through unvalidated user config.","solutions":["Use exactly 'WIKI' or 'HTML' (uppercase).","Validate/normalize user-supplied format strings (e.g. .upper()) before constructing the tool."],"exampleFix":"# before\ntool = WikipediaSearchTool(user_agent='x', extract_format='wiki')\n# after\ntool = WikipediaSearchTool(user_agent='x', extract_format='WIKI')","handlingStrategy":"type-guard","validationCode":"fmt = (extract_format or 'WIKI').upper()\nassert fmt in {'WIKI','HTML'}, \"extract_format must be 'WIKI' or 'HTML'\"","typeGuard":"def is_valid_extract_format(v: str) -> bool:\n    return isinstance(v, str) and v.upper() in {'WIKI', 'HTML'}","tryCatchPattern":null,"preventionTips":["Normalize case before passing.","Don't expose raw user input as extract_format without whitelisting."],"tags":["wikipedia","input-validation","smolagents"],"backgroundTag":"invalid-argument-value","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}