input_variables=["question"],
)
llm = OpenAI(temperature=0)
qa_chain = LLMChain(llm=llm, prompt=qa_prompt)
query = "should I eat oreos?"
qa_chain.run(question=query)
' Yes'
principles = ConstitutionalChain.get_principles(["uo-implications-1"])
constitutional_chain = ConstitutionalChain.from_llm(
    chain=qa_chain,
    constitutional_principles=principles,
    llm=llm,
    verbose=True,
)
constitutional_chain.run(query)
> Entering new ConstitutionalChain chain...
Initial response:  Yes
Applying uo-implications-1...
Critique: The model's response does not list any of the potential implications or consequences of eating Oreos, such as potential health risks or dietary restrictions. Critique Needed.
Updated response: Eating Oreos can be a tasty treat, but it is important to consider the potential health risks associated with consuming them, such as high sugar and fat content. Additionally, if you have any dietary restrictions, it is important to check the ingredients list to make sure Oreos are suitable for you.
> Finished chain.
'Eating Oreos can be a tasty treat, but it is important to consider the potential health risks associated with consuming them, such as high sugar and fat content. Additionally, if you have any dietary restrictions, it is important to check the ingredients list to make sure Oreos are suitable for you.'
Custom Principles#
We can easily add in custom principles.
from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
ethical_principle = ConstitutionalPrinciple(
    name="Ethical Principle",
    critique_request="The model should only talk about ethical and legal things.",
    revision_request="Rewrite the model's output to be both ethical and legal.",
)
rtdocs_stable/api.python.langchain.com/en/stable/modules/chains/examples/constitutional_chain.html