Skip to content

[Bug]: AttributeError: 'str' object has no attribute 'get' #19237

Closed
@jan-stanek

Description

@jan-stanek

Your current environment

vllm 0.9.0.1

🐛 Describe the bug

AttributeError: 'str' object has no attribute 'get' is thrown if tool_choince is not defined correctly:

"tool_choice":{
    "function":"do-something",
    "type":"function"
}

Instead of the correct:

"tool_choice":{
    "function": {"name": "do-something"},
    "type":"function"
}

Log:

ERROR:    Exception in ASGI application                                                                                                                                                                                                                                                                                     
Traceback (most recent call last):                                                                                                                                                                                                                                                                                          
  File "/usr/local/lib/python3.12/dist-packages/uvicorn/protocols/http/httptools_impl.py", line 409, in run_asgi                                                                                                                                                                                                            
    result = await app(  # type: ignore[func-returns-value]                                                                                                                                                                                                                                                                 
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                 
  File "/usr/local/lib/python3.12/dist-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__                                                                                                                                                                                                                  
    return await self.app(scope, receive, send)                                                                                                                                                                                                                                                                             
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                             
  File "/usr/local/lib/python3.12/dist-packages/fastapi/applications.py", line 1054, in __call__                                                                                                                                                                                                                            
    await super().__call__(scope, receive, send)                                                                                                                                                                                                                                                                            
  File "/usr/local/lib/python3.12/dist-packages/starlette/applications.py", line 112, in __call__                                                                                                                                                                                                                           
    await self.middleware_stack(scope, receive, send)                                                                                                                                                                                                                                                                       
  File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/errors.py", line 187, in __call__                                                                                                                                                                                                                      
    raise exc                                                                                                                                                                                                                                                                                                               
  File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/errors.py", line 165, in __call__                                                                                                                                                                                                                      
    await self.app(scope, receive, _send)                                                                                                                                                                                                                                                                                   
  File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/cors.py", line 85, in __call__                                                                                                                                                                                                                         
    await self.app(scope, receive, send)                                                                                                                                                                                                                                                                                    
  File "/usr/local/lib/python3.12/dist-packages/prometheus_fastapi_instrumentator/middleware.py", line 177, in __call__                                                                                                                                                                                                     
    raise exc                                                                                                                                                                                                                                                                                                               
  File "/usr/local/lib/python3.12/dist-packages/prometheus_fastapi_instrumentator/middleware.py", line 175, in __call__                                                                                                                                                                                                     
    await self.app(scope, receive, send_wrapper)                                                                                                                                                                                                                                                                            
  File "/usr/local/lib/python3.12/dist-packages/starlette/middleware/exceptions.py", line 62, in __call__                                                                                                                                                                                                                   
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)                                                                                                                                                                                                                                                
  File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                                                                                                                   
    raise exc                                                                                                                                                                                                                                                                                                               
  File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 42, in wrapped_app                                                                                                                                                                                                                   
    await app(scope, receive, sender)                                                                                                                                                                                                                                                                                       
  File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 714, in __call__                                                                                                                                                                                                                                
    await self.middleware_stack(scope, receive, send)                                                                                                                                                                                                                                                                       
  File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 734, in app                                                                                                                                                                                                                                     
    await route.handle(scope, receive, send)                                                                                                                                                                                                                                                                                
  File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 288, in handle                                                                                                                                                                                                                                  
    await self.app(scope, receive, send)                                                                                                                                                                                                                                                                                    
  File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 76, in app                                                                                                                                                                                                                                      
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)                                                                                                                                                                                                                                                  
  File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 53, in wrapped_app                                                                                                                                                                                                                   
    raise exc                                                                                                                                                                                                                                                                                                               
  File "/usr/local/lib/python3.12/dist-packages/starlette/_exception_handler.py", line 42, in wrapped_app                                                                                                                                                                                                                   
    await app(scope, receive, sender)                                                                                                                                                                                                                                                                                       
  File "/usr/local/lib/python3.12/dist-packages/starlette/routing.py", line 73, in app                                                                                                                                                                                                                                      
    response = await f(request)                                                                                                                                                                                                                                                                                             
               ^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                                             
  File "/usr/local/lib/python3.12/dist-packages/fastapi/routing.py", line 291, in app                                                                                                                                                                                                                                       
    solved_result = await solve_dependencies(                                                                                                                                                                                                                                                                               
                    ^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                               
  File "/usr/local/lib/python3.12/dist-packages/fastapi/dependencies/utils.py", line 666, in solve_dependencies                                                                                                                                                                                                             
    ) = await request_body_to_args(  # body_params checked above                                                                                                                                                                                                                                                            
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                            
  File "/usr/local/lib/python3.12/dist-packages/fastapi/dependencies/utils.py", line 906, in request_body_to_args                                                                                                                                                                                                           
    v_, errors_ = _validate_value_with_model_field(                                                                                                                                                                                                                                                                         
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                         
  File "/usr/local/lib/python3.12/dist-packages/fastapi/dependencies/utils.py", line 706, in _validate_value_with_model_field                                                                                                                                                                                               
    v_, errors_ = field.validate(value, values, loc=loc)                                                                                                                                                                                                                                                                    
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                    
  File "/usr/local/lib/python3.12/dist-packages/fastapi/_compat.py", line 129, in validate                                                                                                                                                                                                                                  
    self._type_adapter.validate_python(value, from_attributes=True),                                                                                                                                                                                                                                                        
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                         
  File "/usr/local/lib/python3.12/dist-packages/pydantic/type_adapter.py", line 421, in validate_python                                                                                                                                                                                                                     
    return self.validator.validate_python(                                                                                                                                                                                                                                                                                  
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                                  
  File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/protocol.py", line 42, in __log_extra_fields__                                                                                                                                                                                                      
    result = handler(data)                                                                                                                                                                                                                                                                                                  
             ^^^^^^^^^^^^^                                                                                                                                                                                                                                                                                                  
  File "/usr/local/lib/python3.12/dist-packages/vllm/entrypoints/openai/protocol.py", line 704, in check_tool_usage                                                                                                                                                                                                         
    specified_function_name = specified_function.get("name")                                                                                                                                                                                                                                                                
                              ^^^^^^^^^^^^^^^^^^^^^^                                                                                                                                                                                                                                                                        
AttributeError: 'str' object has no attribute 'get'  

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions