# Tool call and structured ouput

**URL:** <https://forum.langchain.com/t/tool-call-and-structured-ouput/1891>\
**Category:** LangChain\
**Tags:** python-help\
**Created:** [October 21, 2025, 5:53pm UTC](https://forum.langchain.com/t/tool-call-and-structured-ouput/1891 "2025-10-21T17:53:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yugandhar](https://avatars.discourse-cdn.com/v4/letter/y/fbc32d/32.png) [@yugandhar](https://forum.langchain.com/u/yugandhar)\
**Post date:** [October 21, 2025, 5:53pm UTC](https://forum.langchain.com/t/tool-call-and-structured-ouput/1891/1 "2025-10-21T17:53:30Z")

</div>

I’m new to langchain. I’m using a model in **Standalone mode.**  
In this i have defined a tools and output structures  
I’m using Langchain V1

```auto
import os
import dotenv
from langchain.chat_models import init_chat_model
from langchain.tools import tool
from pydantic import BaseModel, Field

dotenv.load_dotenv()

class NumberOperation(BaseModel):
    """Number operation result."""
    input_number: int = Field(..., description="The input number")
    operation: str = Field(..., description="The operation performed")
    result: int = Field(..., description="The result of the operation")
    
@tool
def magnify_number(number: int) -> int:
    """Magnify a number """
    print("Magnifying number:", number)
    return number * 10

@tool
def maximize_number(number: int) -> int:
    """Maximize a number """
    print("Maximizing number:", number)
    return number * 100

model = init_chat_model(model_provider="openai", model=os.getenv("OPENAI_MODEL"), temperature=0.7)
model_with_tool = model.bind_tools([magnify_number,maximize_number])
model_with_weather_structure = model_with_tool.with_structured_output(NumberOperation)
response = model_with_weather_structure.invoke("Magnify the number 5")
print(response)
response = model_with_weather_structure.invoke("Maximize the number 36")
print(response)

```

i got the following output

```auto
input_number=5 operation='Magnify by factor of 2' result=10
input_number=36 operation='Clarification needed to maximize with rules.' result=0

```

this is not the expected output. what went wrong in this?

---

<div class="post-metadata">

**Author:** ![chester-lc](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@chester-lc](https://forum.langchain.com/u/chester-lc)\
**Post date:** [October 21, 2025, 6:58pm UTC](https://forum.langchain.com/t/tool-call-and-structured-ouput/1891/2 "2025-10-21T18:58:24Z")

</div>

The chat model itself will not execute the tools. It will just reply to you with a request to use the tools (see [tool calling](https://docs.langchain.com/oss/python/langchain/models#tool-calling)).

To execute the tools and return a response following your schema, use an agent— see docs [here](https://docs.langchain.com/oss/python/langchain/agents#structured-output) for agents + structured output.

---

<div class="post-metadata">

**Author:** ![yugandhar](https://avatars.discourse-cdn.com/v4/letter/y/fbc32d/32.png) [@yugandhar](https://forum.langchain.com/u/yugandhar)\
**Post date:** [October 23, 2025, 4:33am UTC](https://forum.langchain.com/t/tool-call-and-structured-ouput/1891/3 "2025-10-23T04:33:26Z")

</div>

Thanks @chester-lc

---

<div class="post-metadata">

**Author:** ![yugandharreddy](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/yugandharreddy/32/2197_2.png) [@yugandharreddy](https://forum.langchain.com/u/yugandharreddy)\
**Post date:** [September 2, 2026, 5:18pm UTC](https://forum.langchain.com/t/tool-call-and-structured-ouput/1891/4 "2026-09-02T17:18:20Z")

</div>

As chester-lc said model itself will not execute the tools. Here you can use the following code to make tool calls without agent.

```auto
for res in response:
    for tool_call in res.tool_calls:
        print("Tool called:", tool_call['name'])
        print("Tool arguments:", tool_call['args'])
        tool_response = None
        if tool_call['name']== "magnify_number":
            tool_response = magnify_number.invoke(tool_call)
        elif tool_call['name']== "maximize_number":
            tool_response = maximize_number.invoke(tool_call)
        print("Tool response:", tool_response)

```

pass the tool response to model to the structured output

---

<div class="post-metadata">

**Author:** ![yugandhar](https://avatars.discourse-cdn.com/v4/letter/y/fbc32d/32.png) [@yugandhar](https://forum.langchain.com/u/yugandhar)\
**Post date:** [September 2, 2026, 5:23pm UTC](https://forum.langchain.com/t/tool-call-and-structured-ouput/1891/5 "2026-09-02T17:23:53Z")

</div>

@yugandharreddy thanks for the code

---

<div class="post-metadata">

**Author:** ![travorcorning](https://avatars.discourse-cdn.com/v4/letter/t/8797f3/32.png) [@travorcorning](https://forum.langchain.com/u/travorcorning)\
**Post date:** [September 3, 2026, 9:20am UTC](https://forum.langchain.com/t/tool-call-and-structured-ouput/1891/6 "2026-09-03T09:20:20Z")

</div>

@yugandharreddy This helped me in writing my own custom state modifier
