Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Can't use mustache/jinja2 templates with an argument named "template" #26058

Open
5 tasks done
ikbenale opened this issue Sep 4, 2024 · 0 comments
Open
5 tasks done
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core

Comments

@ikbenale
Copy link
Contributor

ikbenale commented Sep 4, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • 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).

Example Code

>>> from langchain_core.prompts import PromptTemplate
>>> prompt = PromptTemplate.from_template("Say {template}")
>>> prompt.format(template="foo")
'Say foo'
>>> prompt = PromptTemplate.from_template("Say {{template}}", template_format="mustache")
>>> prompt.format(template="foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alejandro/src/github.com/langchain-ai/langchain/libs/core/langchain_core/prompts/prompt.py", line 179, in format
    return DEFAULT_FORMATTER_MAPPING[self.template_format](self.template, **kwargs)
TypeError: mustache_formatter() got multiple values for argument 'template'
>>> prompt = PromptTemplate.from_template("Say {{template}}", template_format="jinja2")
>>> prompt.format(template="foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/alejandro/src/github.com/langchain-ai/langchain/libs/core/langchain_core/prompts/prompt.py", line 179, in format
    return DEFAULT_FORMATTER_MAPPING[self.template_format](self.template, **kwargs)
TypeError: jinja2_formatter() got multiple values for argument 'template'

Error Message and Stack Trace (if applicable)

File "/Users/alejandro/src/github.com/langchain-ai/langchain/libs/core/langchain_core/prompts/prompt.py", line 179, in format
return DEFAULT_FORMATTER_MAPPING[self.template_format](self.template, **kwargs)
TypeError: mustache_formatter() got multiple values for argument 'template'

Description

  • Trying to format a prompt template in mustache or jinja2 with a template argument
  • LangChain throws a TypeError

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64
Python Version: 3.10.14 (main, Mar 19 2024, 21:46:16) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information

langchain_core: 0.2.38
langchain: 0.2.16
langchain_community: 0.2.16
langsmith: 0.1.98
langchain_experimental: 0.0.65
langchain_openai: 0.1.23
langchain_text_splitters: 0.2.4

Optional packages not installed

langgraph
langserve

Other Dependencies

aiohttp: 3.10.1
async-timeout: 4.0.3
dataclasses-json: 0.6.7
jsonpatch: 1.33
numpy: 1.26.4
openai: 1.40.1
orjson: 3.10.6
packaging: 24.1
pydantic: 2.8.2
PyYAML: 6.0.2
requests: 2.32.3
SQLAlchemy: 2.0.32
tenacity: 8.5.0
tiktoken: 0.7.0
typing-extensions: 4.12.2

@dosubot dosubot bot added Ɑ: core Related to langchain-core 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Sep 4, 2024
efriis added a commit that referenced this issue Sep 20, 2024
- **Description:**  fix "template" not allowed as prompt param
- **Issue:** #26058
- **Dependencies:** none


- [ ] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [ ] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

---------

Co-authored-by: Erick Friis <[email protected]>
sfc-gh-nmoiseyev pushed a commit to sfc-gh-nmoiseyev/langchain that referenced this issue Sep 21, 2024
- **Description:**  fix "template" not allowed as prompt param
- **Issue:** langchain-ai#26058
- **Dependencies:** none


- [ ] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [ ] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

---------

Co-authored-by: Erick Friis <[email protected]>
Sheepsta300 pushed a commit to Sheepsta300/langchain that referenced this issue Oct 1, 2024
- **Description:**  fix "template" not allowed as prompt param
- **Issue:** langchain-ai#26058
- **Dependencies:** none


- [ ] **Add tests and docs**: If you're adding a new integration, please
include
1. a test for the integration, preferably unit tests that do not rely on
network access,
2. an example notebook showing its use. It lives in
`docs/docs/integrations` directory.


- [ ] **Lint and test**: Run `make format`, `make lint` and `make test`
from the root of the package(s) you've modified. See contribution
guidelines for more: https://python.langchain.com/docs/contributing/

Additional guidelines:
- Make sure optional dependencies are imported within a function.
- Please do not add dependencies to pyproject.toml files (even optional
ones) unless they are required for unit tests.
- Most PRs should not touch more than one package.
- Changes should be backwards compatible.
- If you are adding something to community, do not re-import it in
langchain.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

---------

Co-authored-by: Erick Friis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core
Projects
None yet
Development

No branches or pull requests

1 participant