Skip to content

Add code to escape special characters before sending them to OpenAI. Specifically the text {Wallet} caused the openID api to try to do variable substitution, looking for a variable called Wallet. #22

@JohnFunkCode

Description

@JohnFunkCode

The issue occurred when I asked "sumarize the notable bit coin heists from this year"

The semantic search included the split: DocID: 10 SplitID: 1247 that has the following text
"tack which ultimately affected Bybit. The North Korean hackers compromised, we know, the multi-signature wallet provider Safe{Wallet}. It turns out this was conducted through a social engineering attack which targeted one of its developers. And remember, social engineering is now the way these things are happening more and more. Pretty much, you know, a lot of the other infrastructure has been shored up and tightened up. Social engineering, the human factor, is still - has now become the weakest link. According to a new post-mortem report, the point of entry appears to have been a malicious Docker file..."

Note the text {Wallet} occurs in the text

Here is the error dump for the issue

KeyError
KeyError: "Input to PromptTemplate is missing variables {'Wallet'}. Expected: ['Wallet'] Received: ['query_text', 'splits_text']\nNote: if you intended {Wallet} to be part of the string and not a variable, please escape it with double curly braces like: '{{Wallet}}'.\nFor troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/INVALID_PROMPT_INPUT "

Traceback (most recent call last)
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/flask/app.py", line 1498, in call
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/flask/app.py", line 1476, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/johnfunk/Documents/code/securityRAG/app.py", line 64, in query
dc.QueryResponse = generator.generate_response(user_query)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/johnfunk/Documents/code/securityRAG/Experiments/generatorExperiments.py", line 62, in generate_response
response = sequence.invoke({"query_text": query_text, "splits_text": splits_text})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 3023, in invoke
input = context.run(step.invoke, input, config, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/prompts/base.py", line 210, in invoke
return self._call_with_config(

File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/runnables/base.py", line 1925, in _call_with_config
context.run(
^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/runnables/config.py", line 430, in call_func_with_variable_args
return func(input, **kwargs) # type: ignore[call-arg]
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/prompts/base.py", line 184, in _format_prompt_with_error_handling
_inner_input = self._validate_input(inner_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/langchain_core/prompts/base.py", line 178, in _validate_input
raise KeyError(
^
KeyError: "Input to PromptTemplate is missing variables {'Wallet'}. Expected: ['Wallet'] Received: ['query_text', 'splits_text']\nNote: if you intended {Wallet} to be part of the string and not a variable, please escape it with double curly braces like: '{{Wallet}}'.\nFor troubleshooting, visit: https://python.langchain.com/docs/troubleshooting/errors/INVALID_PROMPT_INPUT "
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions