langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
94.04k stars 15.17k forks source link

Cannot inspect schema when working with special type annotations #27510

Open eyurtsev opened 6 days ago

eyurtsev commented 6 days ago

Privileged issue

Issue Content

schema inspection + special type annotations

from langchain_core.tools import tool, InjectedToolArg

@tool
def user_specific_tool(input_data: str, user_id: InjectedToolArg) -> str:
    """Some tool"""
    return f"User {user_id} processed {input_data}"

user_specific_tool.args
chloepan33 commented 6 days ago

Hey @eyurtsev! We are a group of students from UofT interested in this issue. Is it possible we could know more details of this issue and the desire output?

eyurtsev commented 6 days ago

A tool is an association between:

  1. underlying function
  2. a schema that describes the function name, description and its inputs

There are use cases, where some of the tools inputs should not be controllable by the chat model, but dictated by the application logic. (e.g., user_id -- should be associated with the user logged into the application and not chosen by the chat model as that would be a (very serious) security vulnerability)

We use special type annotations to mark arguments as "hidden" from the chat model. This allows us to use the @tool decorator to easily generate a schema that can be presented to a chat model without surfacing other parameters that the chat model should not know about (these parameters will be injected during run time).

FYI I haven't triaged this issue yet to determine whether it manifests itself when used with chat models (there might be another code path used) -- i don't know if this is a high priority issue yet or not, if it's high priority we will likely tackle within a few days time