{"record":{"id":"54525af4a8357f8e","repo":"zylon-ai/private-gpt","slug":"invalid-request-error","errorCode":"INVALID_REQUEST_ERROR","errorMessage":"Configured model does not support function calling","messagePattern":"Configured model does not support function calling","errorType":"exception","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"private_gpt/components/engines/chat/chat_engine.py","lineNumber":869,"sourceCode":"                    thinking=\"\",\n                    signature=f\"sig_{uuid4().hex}\",\n                ),\n            )\n        stream_delta_state.active_block.index = run.block_count\n        run.block_count += 1\n        stream_delta_state.active_block_kind = target_kind\n        handler.emit(stream_delta_state.active_block)\n\n    def initialize_run(\n        self,\n        request: ChatRequest,\n        context_stack: ContextStack | None = None,\n        hooks: list[ToolExecutionHook] | None = None,\n    ) -> _LoopRun:\n        \"\"\"Build initial llm and state for one run.\"\"\"\n        llm = self._llm_component.get_llm(request.system.model)\n        if not isinstance(llm, FunctionCallingLLM):\n            raise ValueError(\"Configured model does not support function calling\")\n\n        if not isinstance(request, ResolvedChatRequest) and context_stack is None:\n            raise ValueError(\"Configured context stack is required\")\n\n        llm_kwargs = ChatLLMParameters.model_validate(request.sampling_params)\n        if request.thinking.enabled and request.thinking.type:\n            llm_kwargs = llm_kwargs.model_copy(\n                update={\n                    \"reasoning_effort\": ReasoningEffort.from_str(request.thinking.type)\n                }\n            )\n        if request.response_format and request.response_format.output_cls:\n            structured = StructuredOutputsParams.from_optional(\n                output_cls=request.response_format.output_cls,\n            )\n            if structured is not None:\n                llm_kwargs = llm_kwargs.model_copy(\n                    update={\"structured_outputs\": structured}","sourceCodeStart":851,"sourceCodeEnd":887,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/engines/chat/chat_engine.py#L851-L887","documentation":"Identical guard in the synchronous ChatEngine.initialize_run: llm = self._llm_component.get_llm(request.system.model) must be a FunctionCallingLLM or the run is aborted with ValueError before the context-stack requirement and sampling-params validation are checked. Tagged INVALID_REQUEST_ERROR, so it is treated as caller error (bad model choice in the request), not an internal fault.","triggerScenarios":"Calling initialize_run / streaming chat APIs with request.system.model pointing at a non-function-calling LLM — completion-only models, generic wrappers, or mocks that don't subclass FunctionCallingLLM.","commonSituations":"Requesting a small/cheap model without tool support while the engine's features (tools, structured output via response_format) require function calling; custom LLM integrations not inheriting FunctionCallingLLM; model id resolving to an unexpected LLM class after provider config changes.","solutions":["Set system.model to a function-calling-capable model in the request","Make custom LLM classes subclass FunctionCallingLLM","Validate the resolved LLM type in a pre-flight check before submitting the request","Use a FunctionCallingLLM-based mock in tests"],"exampleFix":"# before\nrequest.system.model = 'my-completion-model'  # ValueError\n\n# after\nrequest.system.model = 'my-tool-model'  # resolves to FunctionCallingLLM","handlingStrategy":"type-guard","validationCode":"llm = llm_component.get_llm(request.system.model)\nif not isinstance(llm, FunctionCallingLLM):\n    raise InvalidRequestError(f'model {request.system.model!r} lacks function calling')","typeGuard":"from llama_index.core.llms import FunctionCallingLLM\n\ndef is_function_calling_llm(llm) -> TypeGuard[FunctionCallingLLM]:\n    return isinstance(llm, FunctionCallingLLM)","tryCatchPattern":"try:\n    run = engine.initialize_run(request, context_stack)\nexcept ValueError as e:\n    if 'function calling' in str(e):\n        return JSONResponse({'error': {'code': 'INVALID_REQUEST_ERROR', 'message': str(e)}}, 400)\n    raise","preventionTips":["Advertise tool support per model in your model catalog and enforce it client-side","Run isinstance(llm, FunctionCallingLLM) as a pre-flight before initialize_run","Use FunctionCallingLLM-based mocks in engine tests"],"tags":["chat-engine","llm","function-calling","invalid-request"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}