•   about 1 year ago

Dangerous requests in ArangoGraphQAChain

I noticed that if you set allow_dangerous_requests=False, then it raises a "ValueError: In order to use this chain, you must acknowledge that it can make dangerous requests by setting `allow_dangerous_requests` to `True`." Is there any way to execute this chain and just return the query instead of executing it?

  • 4 comments

  •   •   about 1 year ago

    Hey Qasim,

    That is correct, LangChain made this parameter requirement in a previous release for all Chains that interact with user data. Here is the docstring describing this parameter: https://python.langchain.com/api_reference/community/chains/langchain_community.chains.graph_qa.arangodb.ArangoGraphQAChain.html#langchain_community.chains.graph_qa.arangodb.ArangoGraphQAChain.allow_dangerous_requests

    As of the latest release LangChain, the feature of returning the query (instead of executing it) is not supported.

    This functionality however exists in our fork of LangChain, which we we are working towards getting it into the official langchain package.

    The code for this feature is here: https://github.com/arangoml/langchain/blob/master/libs/community/langchain_community/chains/graph_qa/arangodb.py#L60-L62

    If you prefer to use this version of langchain, you can install with this command:

    ```
    pip install git+https://github.com/arangoml/langchain.git@master#subdirectory=libs/community
    ```
    Alternatively, you can always just copy/paste the `ArangoGraphQAChain` code into your Notebook/file so that you don't have to install this package.

    Regards,
    Anthony

  •   •   about 1 year ago

    Hey Anthony,

    Thanks for your response! I copy pasted ArangoGraphQAChain from your fork into my notebook and tested it as follows

    ```
    chain = ArangoGraphQAChain.from_llm(
    llm=llm,
    graph=arango_graph,
    verbose=True,
    allow_dangerous_requests=True,
    return_aql_query=True
    )
    result = chain.invoke("What events occurred in Algeria in January 1997")
    print(result)
    ```
    Unfortunately, I ran into an error :(
    I have the following packages

    langchain==0.3.19
    langchain-core==0.3.40
    langchain-community==0.3.18

    Error Traceback shown below

    ```
    ---------------------------------------------------------------------------
    ValueError Traceback (most recent call last)
    in ()
    6 return_aql_query=True
    7 )
    ----> 8 result = chain.invoke("What events occurred in Algeria in January 1997")
    9 print(result)

    3 frames
    /usr/local/lib/python3.11/dist-packages/langchain/chains/base.py in invoke(self, input, config, **kwargs)
    168 except BaseException as e:
    169 run_manager.on_chain_error(e)
    --> 170 raise e
    171 run_manager.on_chain_end(outputs)
    172

    /usr/local/lib/python3.11/dist-packages/langchain/chains/base.py in invoke(self, input, config, **kwargs)
    158 self._validate_inputs(inputs)
    159 outputs = (
    --> 160 self._call(inputs, run_manager=run_manager)
    161 if new_arg_supported
    162 else self._call(inputs)

    in _call(self, inputs, run_manager)
    222
    223 try:
    --> 224 aql_result = aql_execution_func(aql_query, {"top_k": self.top_k})
    225 except (AQLQueryExecuteError, AQLQueryExplainError) as e:
    226 aql_error = e.error_message

    /usr/local/lib/python3.11/dist-packages/langchain_community/graphs/arangodb_graph.py in query(self, query, top_k, **kwargs)
    116
    117 cursor = self.__db.aql.execute(query, **kwargs)
    --> 118 return [doc for doc in itertools.islice(cursor, top_k)]
    119
    120 @classmethod

    ValueError: Stop argument for islice() must be None or an integer: 0 <= x <= sys.maxsize.
    ```

  •   •   about 1 year ago

    Good point Qasim, thanks for catching that. This is because copying the ArangoGraphQAChain class directly from our Fork means that the ArangoGraph class version you are using from langchain_community will no longer work.

    To solve this, you have 2 options:

    1. Instead of copying the ArangoGraphQAChain code, simply pip install using the command specified above ^
    2. Copy the ArangoGraph class code as well, which is found here: https://github.com/arangoml/langchain/blob/master/libs/community/langchain_community/graphs/arangodb_graph.py

    This will allow you to run the code you specified.

    One small correction however:

    ```
    ```
    chain = ArangoGraphQAChain.from_llm(
    llm=llm,
    graph=arango_graph,
    verbose=True,
    allow_dangerous_requests=True,
    # return_aql_query=True
    )

    chain.execute_aql_query = False # this is how you can disable query execution

    result = chain.invoke("What events occurred in Algeria in January 1997")

    print(result) # The returned result should be a dictionary, where the "result" key contains the Generated AQL Query
    ```

    Let me know how it goes

  •   •   about 1 year ago

    I did the pip install this time and it works! Thanks for the help :D This is gonna let me add a nice feature to my submission, hopefully :)

Comments are closed.