Skip to content

[BUG] PGSearchTool does not work #3667

@AlexisGitHu

Description

@AlexisGitHu

Description

PGSearchTool does not work providing a db_uri.

Steps to Reproduce

Instantiate the PGSearchTool class providing a db_uri.

Expected behavior

It should not trigger an error on db_uri as it is being passed to the init method

Screenshots/Code snippets

Image

Operating System

Ubuntu 22.04

Python Version

3.12

crewAI Version

0.201.1

crewAI Tools Version

0.75.0

Virtual Environment

Venv

Evidence

Error trace:

  File "/home/alexis/github/crewai-test-pcai/backend/v1/crew.py", line 127, in consultant
    pg_sql = PGSearchTool(
        db_uri=os.environ.get("PG_URI"),
    ...<5 lines>...
        },
    )
  File "/home/alexis/github/crewai-test-pcai/backend/.venv/lib/python3.13/site-packages/crewai_tools/tools/pg_search_tool/pg_search_tool.py", line 36, in __init__
    self.add(table_name, data_type=DataType.POSTGRES, metadata={"db_uri": self.db_uri})
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexis/github/crewai-test-pcai/backend/.venv/lib/python3.13/site-packages/crewai_tools/tools/pg_search_tool/pg_search_tool.py", line 45, in add
    super().add(f"SELECT * FROM {table_name};", **kwargs)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexis/github/crewai-test-pcai/backend/.venv/lib/python3.13/site-packages/crewai_tools/tools/rag/rag_tool.py", line 192, in add
    self.adapter.add(*args, **kwargs)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/alexis/github/crewai-test-pcai/backend/.venv/lib/python3.13/site-packages/crewai_tools/adapters/crewai_rag_adapter.py", line 188, in add
    loader_result: LoaderResult = loader.load(source_content)
                                  ~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/home/alexis/github/crewai-test-pcai/backend/.venv/lib/python3.13/site-packages/crewai_tools/rag/loaders/postgres_loader.py", line 30, in load
    raise ValueError("Database URI is required for PostgreSQL loader")
ValueError: Database URI is required for PostgreSQL loader

Possible Solution

The following script was modified to assess the issue crewai_tools/rag/loaders/postgres_loader.py. Concretely on line 188.

Adding metadata variable to parameters of the function LoaderResult.load() resolved the issue:

loader_result: LoaderResult = loader.load(source_content, metadata=metadata)

Additional context

No more context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions