box_ai_extract_structured_using_template_tool
Extract structured data from Box files using AI and a predefined template. Process files to pull relevant information based on the template, returning results in JSON format.
Instructions
Extract structured data from files in Box using AI with a specified template. This tool allows users to extract structured data from files by using a predefined template. The AI processes the files and extracts the relevant information based on the provided template. Args: ctx (Context): The context object containing the request and lifespan context. file_ids (List[str]): The IDs of the files to read. template_key (str): The ID of the template to use for extraction. ai_agent_id (Optional[str]): The ID of the AI agent to use for processing. Returns: dict: The extracted structured data in a json string format.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ai_agent_id | No | ||
| file_ids | Yes | ||
| template_key | Yes |
Implementation Reference
- src/tools/box_tools_ai.py:215-249 (handler)The main asynchronous handler function for the box_ai_extract_structured_using_template_tool. It retrieves the Box client from context and delegates to the underlying box_ai_extract_structured_using_template function from the SDK.async def box_ai_extract_structured_using_template_tool( ctx: Context, file_ids: List[str], template_key: str, ai_agent_id: Optional[str] = None, ) -> dict: """ Extract structured data from one or more files and return a SINGLE metadata instance. This tool analyzes the provided file(s) and extracts information to populate a single metadata instance based on the specified template. When multiple files are provided, Box AI combines information from ALL files to create ONE complete metadata record. Use cases: - Single file: Extract metadata from one receipt, invoice, or document - Multiple files: Combine data from multiple sources into one metadata instance (e.g., extract customer info from both a contract PDF and a supporting letter) NOT for batch processing: If you need to extract metadata from multiple files as separate instances, call this tool once per file in a loop. Args: ctx (Context): The context object containing the request and lifespan context. file_ids (List[str]): The IDs of the files to read. template_key (str): The ID of the template to use for extraction. ai_agent_id (Optional[str]): The ID of the AI agent to use for processing. Returns: dict: The extracted structured data in a json string format. """ box_client = get_box_client(ctx) response = box_ai_extract_structured_using_template( box_client, file_ids, template_key, ai_agent_id=ai_agent_id ) return response
- src/tool_registry/ai_tools.py:18-29 (registration)The registration function that decorates the box_ai_extract_structured_using_template_tool (line 24) with mcp.tool() to register it in the FastMCP server.def register_ai_tools(mcp: FastMCP): mcp.tool()(box_ai_ask_file_single_tool) mcp.tool()(box_ai_ask_file_multi_tool) mcp.tool()(box_ai_ask_hub_tool) mcp.tool()(box_ai_extract_freeform_tool) mcp.tool()(box_ai_extract_structured_using_fields_tool) mcp.tool()(box_ai_extract_structured_using_template_tool) mcp.tool()(box_ai_extract_structured_enhanced_using_fields_tool) mcp.tool()(box_ai_extract_structured_enhanced_using_template_tool) mcp.tool()(box_ai_agent_info_by_id_tool) mcp.tool()(box_ai_agents_list_tool) mcp.tool()(box_ai_agents_search_by_name_tool)
- src/tool_registry/ai_tools.py:1-15 (registration)Import statement that brings in the box_ai_extract_structured_using_template_tool from src/tools/box_tools_ai.py for registration.from mcp.server.fastmcp import FastMCP from tools.box_tools_ai import ( box_ai_agent_info_by_id_tool, box_ai_agents_list_tool, box_ai_agents_search_by_name_tool, box_ai_ask_file_multi_tool, box_ai_ask_file_single_tool, box_ai_ask_hub_tool, box_ai_extract_freeform_tool, box_ai_extract_structured_enhanced_using_fields_tool, box_ai_extract_structured_enhanced_using_template_tool, box_ai_extract_structured_using_fields_tool, box_ai_extract_structured_using_template_tool, )