{"record":{"id":"38a0926262b7089a","repo":"huggingface/smolagents","slug":"user-agent-is-required-provide-a-meaningful-ident","errorCode":null,"errorMessage":"User-agent is required. Provide a meaningful identifier for your project.","messagePattern":"User-agent is required\\. Provide a meaningful identifier for your project\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/smolagents/default_tools.py","lineNumber":602,"sourceCode":"    }\n    output_type = \"string\"\n\n    def __init__(\n        self,\n        user_agent: str = \"Smolagents (myemail@example.com)\",\n        language: str = \"en\",\n        content_type: str = \"text\",\n        extract_format: str = \"WIKI\",\n    ):\n        super().__init__()\n        try:\n            import wikipediaapi\n        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","sourceCodeStart":584,"sourceCodeEnd":620,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/default_tools.py#L584-L620","documentation":"Raised by WikipediaSearchTool.__init__ when user_agent is empty/None. The wikipedia-api library requires a meaningful User-Agent per Wikimedia's API policy, so smolagents enforces it at construction with a ValueError.","triggerScenarios":"WikipediaSearchTool() with no user_agent argument (if no acceptable default applies) or explicitly passing user_agent='' / None.","commonSituations":"Copy-pasting quickstart code that omits user_agent, or assuming a generic default is used. Wikimedia may block default/empty agents, hence the strict check.","solutions":["Pass a descriptive user_agent identifying your project, e.g. WikipediaSearchTool(user_agent='my-agent (contact@example.com)').","Set the value from config/env so it is consistent across deployments."],"exampleFix":"# before\ntool = WikipediaSearchTool()  # ValueError\n# after\ntool = WikipediaSearchTool(user_agent='my-research-bot/1.0 (https://example.com; me@example.com)')","handlingStrategy":"validation","validationCode":"if not user_agent: raise ValueError('user_agent required')\ntool = WikipediaSearchTool(user_agent=user_agent)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize a project-wide user_agent string in config.","Treat user_agent as required config for any Wikipedia integration."],"tags":["wikipedia","input-validation","user-agent","smolagents"],"backgroundTag":"missing-required-parameter","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}