Skip to content

TypeError in langchain_anthropic/middleware/bash.py #34068

@sarahec

Description

@sarahec

Checked other resources

  • This is a bug, not a usage question.
  • I added a clear and descriptive title that summarizes this issue.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
  • This is not related to the langchain-community package.
  • I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.

Package (Required)

  • langchain
  • langchain-openai
  • langchain-anthropic
  • langchain-classic
  • langchain-core
  • langchain-cli
  • langchain-model-profiles
  • langchain-tests
  • langchain-text-splitters
  • langchain-chroma
  • langchain-deepseek
  • langchain-exa
  • langchain-fireworks
  • langchain-groq
  • langchain-huggingface
  • langchain-mistralai
  • langchain-nomic
  • langchain-ollama
  • langchain-perplexity
  • langchain-prompty
  • langchain-qdrant
  • langchain-xai
  • Other / not sure / general

Example Code (Python)

Running pytest while building langchain-anthropic for nixpkgs

Error Message and Stack Trace (if applicable)

____________________________ test_creates_bash_tool ____________________________

monkeypatch = <_pytest.monkeypatch.MonkeyPatch object at 0x7ffff2b13bb0>

    def test_creates_bash_tool(monkeypatch: pytest.MonkeyPatch) -> None:
        """Test that ClaudeBashToolMiddleware creates a tool named 'bash'."""
>       middleware = ClaudeBashToolMiddleware()
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/unit_tests/middleware/test_bash.py:16: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <langchain_anthropic.middleware.bash.ClaudeBashToolMiddleware object at 0x7ffff29a5be0>
workspace_root = None

    def __init__(
        self,
        workspace_root: str | None = None,
        *,
        startup_commands: tuple[str, ...] | list[str] | str | None = None,
        shutdown_commands: tuple[str, ...] | list[str] | str | None = None,
        execution_policy: Any | None = None,
        redaction_rules: tuple[Any, ...] | list[Any] | None = None,
        tool_description: str | None = None,
        env: dict[str, Any] | None = None,
    ) -> None:
        """Initialize middleware for Claude's native bash tool.
    
        Args:
            workspace_root: Base directory for the shell session.
                If omitted, a temporary directory is created.
            startup_commands: Optional commands executed after the session starts.
            shutdown_commands: Optional commands executed before session shutdown.
            execution_policy: Execution policy controlling timeouts and limits.
            redaction_rules: Optional redaction rules to sanitize output.
            tool_description: Optional override for tool description.
            env: Optional environment variables for the shell session.
        """
>       super().__init__(
            workspace_root=workspace_root,
            startup_commands=startup_commands,
            shutdown_commands=shutdown_commands,
            execution_policy=execution_policy,
            redaction_rules=redaction_rules,
            tool_description=tool_description,
            tool_name=BASH_TOOL_NAME,
            shell_command=("/bin/bash",),
            env=env,
        )
E       TypeError: ShellToolMiddleware.__init__() got an unexpected keyword argument 'tool_name'

langchain_anthropic/middleware/bash.py:45: TypeError

Description

test_creates_bash_tool and test_replaces_tool_with_claude_descriptor both fail with the same Pydantic error while testing.

System Info

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    anthropicbugRelated to a bug, vulnerability, unexpected error with an existing feature

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions