{"record":{"id":"b020c4a788301d04","repo":"zylon-ai/private-gpt","slug":"context-filter-is-required","errorCode":null,"errorMessage":"context_filter is required","messagePattern":"context_filter is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/tools/builders/semantic_search_builder.py","lineNumber":91,"sourceCode":"        embedding_component: EmbeddingComponent,\n        ingest_component: IngestComponent,\n        parse_component: ParseComponent,\n        prompt_builder_service: PromptBuilderService,\n    ) -> None:\n        self.settings = settings\n        self.llm_component = llm_component\n        self.vector_store_component = vector_store_component\n        self.node_store_component = node_store_component\n        self.embedding_component = embedding_component\n        self.ingest_component = ingest_component\n        self.parse_component = parse_component\n        self.prompt_builder_service = prompt_builder_service\n\n    async def _validate_context(\n        self, context_filter: ContextFilter | None\n    ) -> ContextFilter:\n        if not context_filter:\n            raise ValueError(\"context_filter is required\")\n\n        if not context_filter.collection:\n            raise ValueError(\"collection is required in context\")\n\n        # If artifacts are provided, verify the related required indexes are ready\n        # or throw an error\n        artifacts = (\n            list(set(context_filter.artifacts)) if context_filter.artifacts else None\n        )\n        if artifacts:\n            tasks: list[Coroutine[Any, Any, None]] = []\n            for artifact in artifacts:\n                vector_artifact_index = VectorArtifactIndex(\n                    collection=context_filter.collection,\n                    artifact=artifact,\n                    vector_store_component=self.vector_store_component,\n                    node_store_component=self.node_store_component,\n                    embedding_component=self.embedding_component,","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/tools/builders/semantic_search_builder.py#L73-L109","documentation":"ValueError from SemanticSearchToolBuilder._validate_context: the semantic search tool requires a context_filter argument, and it was passed as None or omitted. The tool has no default corpus to search, so the filter is mandatory before any retrieval happens.","triggerScenarios":"Invoking the semantic search tool function with context_filter=None or without the parameter; _validate_context is the first step of the tool's execution path.","commonSituations":"Agent/framework call omits the context argument; tool schema filled with defaults; new integration constructs the tool call payload manually and drops context_filter.","solutions":["Pass a ContextFilter instance as context_filter when calling the semantic search tool.","Ensure the tool-calling layer (agent/LLM tool schema) marks context_filter as required so it is always serialized."],"exampleFix":"# before\nresult = await semantic_search_tool(query=\"revenue 2024\")\n\n# after\nfrom private_gpt.chat.input_models import ContextFilter\nresult = await semantic_search_tool(query=\"revenue 2024\", context_filter=ContextFilter(collection=\"default\"))","handlingStrategy":"validation","validationCode":"if context_filter is None:\n    raise ValueError(\"semantic search requires context_filter\")\nresult = await semantic_search_tool(query=q, context_filter=context_filter)","typeGuard":"from private_gpt.chat.input_models import ContextFilter\n\ndef is_valid_context_filter(cf: ContextFilter | None) -> bool:\n    return cf is not None and bool(cf.collection)","tryCatchPattern":null,"preventionTips":["Mark context_filter required in the tool schema exposed to the agent.","Centralize ContextFilter construction in one helper that refuses to return None."],"tags":["validation","semantic-search","tool-input"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}