01 tools tool creating

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 9:54 AM on 8/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards
2
New cards
What is the simplest way to create a tool in LangChain?
The `@tool` decorator.
3
New cards
By default; what becomes a tool's description when using the `@tool` decorator?
The function's docstring.
4
New cards
Why are type hints required when defining a tool with `@tool`?
Because they define the tool's input schema.
5
New cards
By default; where does a tool's name come from?
The function name.
6
New cards
How do you override a tool's default name?
Via `@tool('custom_name')`.
7
New cards
How do you override a tool's auto-generated description?
Via `@tool('name'; description='...')`.
8
New cards
What happens if the LLM passes an invalid value to a tool parameter defined via a Pydantic `args_schema` (e.g. `units='kelvin'` for a `Literal['celsius'; 'fahrenheit']` field)?
Pydantic raises a validation error.
9
New cards
What three things does a Pydantic model passed via `args_schema` give you?
Validation of invalid values; automatic JSON Schema generation that LangChain passes to the LLM; and per-field descriptions that end up in the LLM's prompt.
10
New cards
Without `args_schema`; how does LangChain determine a tool's schema?
It parses the function signature itself; which supports only limited types (str; int; bool) and has no value validation.
11
New cards
With `args_schema`; what additional type support becomes available compared to plain function signature parsing?
Complex types such as `Literal`; `Enum`; and nested models.
12
New cards
With `args_schema`; where do per-parameter descriptions come from instead of the docstring?
From `Field()` on each field of the Pydantic model.
13
New cards
What happens under the hood when a Pydantic model is used as a tool's `args_schema`?
LangChain automatically converts the Pydantic model into a JSON Schema and hands it to the LLM; which then generates a strictly structured tool call with valid arguments.
14
New cards
What is the `config` parameter name reserved for in a tool function signature?
It's reserved for passing `RunnableConfig` to tools internally.
15
New cards
What is the `runtime` parameter name reserved for in a tool function signature?
It's reserved for the `ToolRuntime` parameter; used to access state; context; and store.
16
New cards
What happens if you use `config` or `runtime` as your own tool argument names?
It causes errors during execution; since these names are reserved.
17
New cards
python from langchain.tools import ________ @tool def search_database(query: str; limit: int = 10) -> str: '''Search the customer database for records matching the query. Args: query: Search terms to look for limit: Maximum number of results to return ''' return f'Found {limit} results for '{query}''
```python from langchain.tools import tool @tool def search_database(query: str; limit: int = 10) -> str: '''Search the customer database for records matching the query. Args: query: Search terms to look for limit: Maximum number of results to return ''' return f'Found {limit} results for '{query}'' ```
18
New cards
python @tool('________') # Custom name def search(query: str) -> str: '''Search the web for information.''' return f'Results for: {query}' print(search.name) # web_search
```python @tool('web_search') # Custom name def search(query: str) -> str: '''Search the web for information.''' return f'Results for: {query}' print(search.name) # web_search ```
19
New cards
python @tool('calculator'; ________='Performs arithmetic calculations. Use this for any math problems.') def calc(expression: str) -> str: '''Evaluate mathematical expressions.''' return str(eval(expression))
```python @tool('calculator'; description='Performs arithmetic calculations. Use this for any math problems.') def calc(expression: str) -> str: '''Evaluate mathematical expressions.''' return str(eval(expression)) ```
20
New cards
python from pydantic import BaseModel; Field from typing import Literal class WeatherInput(BaseModel): '''Input for weather queries.''' location: str = Field(description='City name or coordinates') units: ________['celsius'; 'fahrenheit'] = Field( default='celsius'; description='Temperature unit preference' ) include_forecast: bool = Field( default=False; description='Include 5-day forecast' ) @tool(________=WeatherInput) def get_weather(location: str; units: str = 'celsius'; include_forecast: bool = False) -> str: '''Get current weather and optional forecast.''' ...
```python from pydantic import BaseModel; Field from typing import Literal class WeatherInput(BaseModel): '''Input for weather queries.''' location: str = Field(description='City name or coordinates') units: Literal['celsius'; 'fahrenheit'] = Field( default='celsius'; description='Temperature unit preference' ) include_forecast: bool = Field( default=False; description='Include 5-day forecast' ) @tool(args_schema=WeatherInput) def get_weather(location: str; units: str = 'celsius'; include_forecast: bool = False) -> str: '''Get current weather and optional forecast.''' ... ```