Sameer Mahajan
Sameer Mahajan

Reputation: 598

bedrock: ValidationException calling InvokeModelWithResponseStream: Malformed input request: string[Observation] does not match pattern ^(\|+|User:)$,

I have enabled model Titan Text G1 - Express in my AWS Bedrock.

I got the model id for this to be amazon.titan-text-express-v1 from https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html

I setup my credentials and trying to access it as:

from crewai import Agent
from langchain_community.llms import Bedrock

llm = Bedrock(credentials_profile_name="default", model_id="amazon.titan-text-express-v1")

my_agent = Agent(
        role = "my role",
        goal = f"my goal ",
        verbose = True,
        llm=llm,
        backstory = """my backstory"""
    )

When i eventually get an error of:

 File "<my path>/python3.12/site-packages/langchain_core/language_models/llms.py", line 442, in stream
    for chunk in self._stream(
  File "<my path>/python3.12/site-packages/langchain_community/llms/bedrock.py", line 655, in _prepare_input_and_invoke_stream
    raise ValueError(f"Error raised by bedrock service: {e}")
ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModelWithResponseStream operation: The provided model identifier is invalid.

I think this was because I was using us-east-2 region in my configuration whereas the bedrock model was in region us-east-1 However when I change that I get an error of

 File "<my path>/python3.12/site-packages/langchain_community/llms/bedrock.py", line 655, in _prepare_input_and_invoke_stream
    raise ValueError(f"Error raised by bedrock service: {e}")    
ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModelWithResponseStream operation: Malformed input request: string [
    Observation] does not match pattern ^(\|+|User:)$, please reformat your input and try again.

any ideas?

Upvotes: 0

Views: 928

Answers (0)

Related Questions