StrOutputParserimport jsondef parse_or_fix(text: str, config: RunnableConfig):    fixing_chain = (        ChatPromptTemplate.from_template(            "Fix the following text:\n\n```text\n{input}\n```\nError: {error}"            " Don't narrate, just respond with the fixed data."        )        | ChatOpenAI()        | StrOutputParser()    )    for _ in range(3):        try:            return json.loads(text)        except Exception as e:            text = fixing_chain.invoke({"input": text, "error": e}, config)    return "Failed to parse"from langchain.callbacks import get_openai_callbackwith get_openai_callback() as cb:    RunnableLambda(parse_or_fix).invoke("{foo: bar}", {"tags": ["my-tag"], "callbacks": [cb]})    print(cb)    Tokens Used: 65        Prompt Tokens: 56        Completion Tokens: 9    Successful Requests: 1    Total Cost (USD): $0.00010200000000000001PreviousAdd fallbacksNextUse RunnableParallel/RunnableMapAccepting a Runnable ConfigCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.
You can use arbitrary functions in the pipeline
You can use arbitrary functions in the pipeline ->: StrOutputParserimport jsondef parse_or_fix(text: str, config: RunnableConfig):    fixing_chain = (        ChatPromptTemplate.from_template(            "Fix the following text:\n\n```text\n{input}\n```\nError: {error}"            " Don't narrate, just respond with the fixed data."        )        | ChatOpenAI()        | StrOutputParser()    )    for _ in range(3):        try:            return json.loads(text)        except Exception as e:            text = fixing_chain.invoke({"input": text, "error": e}, config)    return "Failed to parse"from langchain.callbacks import get_openai_callbackwith get_openai_callback() as cb:    RunnableLambda(parse_or_fix).invoke("{foo: bar}", {"tags": ["my-tag"], "callbacks": [cb]})    print(cb)    Tokens Used: 65        Prompt Tokens: 56        Completion Tokens: 9    Successful Requests: 1    Total Cost (USD): $0.00010200000000000001PreviousAdd fallbacksNextUse RunnableParallel/RunnableMapAccepting a Runnable ConfigCommunityDiscordTwitterGitHubPythonJS/TSMoreHomepageBlogCopyright ¬© 2023 LangChain, Inc.