Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Prompt component extract invalid input variable #6893

Open
yangxikun opened this issue Mar 1, 2025 · 1 comment
Open

Prompt component extract invalid input variable #6893

yangxikun opened this issue Mar 1, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@yangxikun
Copy link

Bug Description

Image

Reproduction

Prompt Template value:

Generate {num} randomly json data.

Output format:
```
[
	{{
	    "name": "mike",
	    "age": 27
	}}
]
```

Expected behavior

	{{
	    "name": "mike",
	    "age": 27
	}}

Should not consider as a variable.

Who can help?

No response

Operating System

mac

Langflow Version

main

Python Version

3.12

Screenshot

No response

Flow File

No response

@yangxikun yangxikun added the bug Something isn't working label Mar 1, 2025
Copy link

dosubot bot commented Mar 1, 2025

To address the issue with the prompt component extracting input variables incorrectly when using JSON-like syntax, you can utilize the _fix_variable function from the api_utils.py file. This function is designed to handle and correct input variables that contain invalid characters or formats.

Here's a brief guide on how to use the _fix_variable function to resolve this issue:

  1. Identify Invalid Characters: The function will remove any invalid characters defined in _INVALID_CHARACTERS, such as spaces, commas, and brackets, from the input variables.

  2. Correct JSON-like Syntax: The function ensures that JSON-like variables are correctly identified and processed by temporarily replacing {{ and }} to avoid treating them as invalid during processing.

  3. Example Usage:

    def fix_input_variable(var):
        invalid_chars = []
        wrong_variables = []
        fixed_var, invalid_chars, wrong_variables = _fix_variable(var, invalid_chars, wrong_variables)
        return fixed_var, invalid_chars, wrong_variables
    
    # Example usage
    input_var = "1invalid_var_name"
    fixed_var, invalid_chars, wrong_variables = fix_input_variable(input_var)
    
    print("Fixed Variable:", fixed_var)
    print("Invalid Characters:", invalid_chars)
    print("Wrong Variables:", wrong_variables)

By using this function, you can ensure that the JSON-like syntax in your prompt is not mistakenly treated as a variable, thus preventing the error you encountered [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@yangxikun yangxikun changed the title Prompt component extract input variables failed Prompt component extract invalid input variable Mar 1, 2025
yangxikun pushed a commit to yangxikun/langflow that referenced this issue Mar 1, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant