Skip to content

[BUG] Tool spec normalization #124

Closed
Closed
@awsarron

Description

@awsarron

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

0.1.5

Python Version

3.13.3

Operating System

macOS

Installation Method

pip

Steps to Reproduce

  1. Create a module tool with TOOL_SPEC defined. In the tool spec, include deeply nested objects.
  2. Create an agent with the tool and check its tool configuration after tool loading:
from strands import Agent
from my_tools import test_nested_tool

agent = Agent(tools=[test_nested_tool])
print(agent.tool_config)

Expected Behavior

Expected loaded tools with deeply nested objects in the tool spec to preserve the nesting.

Actual Behavior

Deeply nested object structures are not preserved, leading to context loss in the specification provided to the model during inference.

Additional Context

Example provided tool spec:

{
    "name": "generate_income_assessment",
    "description": "Generate an income assessment report",
    "inputSchema": {
        "json": {
            "type": "object",
            "required": [
                "application_id",
                "assessment_type",
                "assessment_criteria"
            ],
            "properties": {
                "application_id": {
                    "type": "string",
                    "description": "The ID of the application being assessed"
                },
                "assessment_type": {
                    "type": "string",
                    "description": "Type of assessment being performed",
                    "const": "INCOME"
                },
                "assessment_criteria": {
                    "type": "object",
                    "required": [
                        "verify_application_document",
                        "verify_payslip_document", 
                        "verify_bank_statements",
                        "verify_employer_matches",
                        "verify_salary_matches"
                    ],
                    "properties": {
                        "verify_application_document": {
                            "type": "object",
                            "properties": {
                                "question": { 
                                    "const": "Verify application document is present",
                                    "description": "A specific evaluation criteria that must be assessed as part of the income verification process"
                                },
                                "result": { 
                                    "type": "string",
                                    "enum": ["PASS", "FAIL", "UNKNOWN"],
                                    "description": "The outcome of the assessment check: PASS indicates criteria are met, FAIL indicates criteria are not met, or UNKNOWN if insufficient information is available"
                                },
                                "explanation": { 
                                    "type": "string",
                                    "description": "A concise justification supporting the result, including evidence and reasoning"
                                }
                            },
                            "required": ["question", "result", "explanation"]
                        },
                        "verify_payslip_document": {
                            "type": "object",
                            "properties": {
                                "question": { 
                                    "const": "Verify payslip document is present",
                                    "description": "A specific evaluation criteria that must be assessed as part of the income verification process"
                                },
                                "result": { 
                                    "type": "string",
                                    "enum": ["PASS", "FAIL", "UNKNOWN"],
                                    "description": "The outcome of the assessment check: PASS indicates criteria are met, FAIL indicates criteria are not met, or UNKNOWN if insufficient information is available"
                                },
                                "explanation": { 
                                    "type": "string",
                                    "description": "A concise justification supporting the result, including evidence and reasoning"
                                }
                            },
                            "required": ["question", "result", "explanation"]
                        },
                        "verify_bank_statements": {
                            "type": "object",
                            "properties": {
                                "question": { 
                                    "const": "Verify bank statements are present",
                                    "description": "A specific evaluation criteria that must be assessed as part of the income verification process"
                                },
                                "result": { 
                                    "type": "string",
                                    "enum": ["PASS", "FAIL", "UNKNOWN"],
                                    "description": "The outcome of the assessment check: PASS indicates criteria are met, FAIL indicates criteria are not met, or UNKNOWN if insufficient information is available"
                                },
                                "explanation": { 
                                    "type": "string",
                                    "description": "A concise justification supporting the result, including evidence and reasoning"
                                }
                            },
                            "required": ["question", "result", "explanation"]
                        },
                        "verify_employer_matches": {
                            "type": "object", 
                            "properties": {
                                "question": { 
                                    "const": "Verify employer matches across documents",
                                    "description": "A specific evaluation criteria that must be assessed as part of the income verification process"
                                },
                                "result": { 
                                    "type": "string",
                                    "enum": ["PASS", "FAIL", "UNKNOWN"],
                                    "description": "The outcome of the assessment check: PASS indicates criteria are met, FAIL indicates criteria are not met, or UNKNOWN if insufficient information is available"
                                },
                                "explanation": { 
                                    "type": "string",
                                    "description": "A concise justification supporting the result, including evidence and reasoning"
                                }
                            },
                            "required": ["question", "result", "explanation"]
                        },
                        "verify_salary_matches": {
                            "type": "object",
                            "properties": {
                                "question": { 
                                    "const": "Verify salary matches payslip",
                                    "description": "A specific evaluation criteria that must be assessed as part of the income verification process"
                                },
                                "result": { 
                                    "type": "string",
                                    "enum": ["PASS", "FAIL", "UNKNOWN"],
                                    "description": "The outcome of the assessment check: PASS indicates criteria are met, FAIL indicates criteria are not met, or UNKNOWN if insufficient information is available"
                                },
                                "explanation": { 
                                    "type": "string",
                                    "description": "A concise justification supporting the result, including evidence and reasoning"
                                }
                            },
                            "required": ["question", "result", "explanation"]
                        }
                    },
                    "additionalProperties": False
                }
            }
        }
    }
}

After normalization:

{
  "toolSpec": {
    "name": "generate_income_assessment",
    "description": "Generate an income assessment report",
    "inputSchema": {
      "json": {
        "type": "object",
        "properties": {
          "application_id": {
            "type": "string",
            "description": "The ID of the application being assessed"
          },
          "assessment_type": {
            "type": "string",
            "description": "Type of assessment being performed"
          },
          "assessment_criteria": {
            "type": "object",
            "description": "Property assessment_criteria"
          }
        },
        "required": [
          "application_id",
          "assessment_type",
          "assessment_criteria"
        ]
      }
    }
  }
}

Possible Solution

Fix tool spec normalization to preserve deeply nested objects.

Related Issues

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions