Loading...
Loading...
Give LLMs the ability to call external functions — defining tools, handling calls, and reliable tool-use systems
User: 'Book a flight to London next Tuesday'
1. LLM analyzes request
2. LLM outputs: search_flights('London', '2026-05-19')
3. Your code executes the function
4. Results returned to LLM
5. LLM generates natural language responsetool = {
'type': 'function',
'function': {
'name': 'search_hotels',
'description': 'Find hotels in a city',
'parameters': {
'type': 'object',
'properties': {
'city': {'type': 'string'},
'check_in': {'type': 'string'},
'max_price': {'type': 'number'}
},
'required': ['city', 'check_in']
}
}
}User Prompt -> LLM generates -> tool_calls? -> Yes: Parse -> Execute -> Return -> LLM
|
No: Return response| Issue | Mitigation |
|---|---|
| SQL injection | Parameterized queries |
| Shell injection | Avoid shell tools |
| Data exfiltration | Audit tool access |
| Cost explosion | Rate limits, max calls |
Define three tools for an e-commerce assistant: get_user_info, search_products, place_order.