Skip to content

For New Contributors: Use SecretStr for api_keys #12165

@eyurtsev

Description

@eyurtsev

Updated: 20233-12-06

Hello everyone! thank you all for your contributions! We've made a lot of progress with SecretStrs in the code base.

First time contributors -- hope you had fun learning how to work in the code base and thanks for putting in the time. All contributors -- thanks for all your efforts in improving LangChain.

We'll create a new first time issue in a few months.


Hello LangChain community,

We're always happy to see more folks getting involved in contributing to the LangChain codebase.

This is a good first issue if you want to learn more about how to set up
for development in the LangChain codebase.

Goal

Your contribution will make it safer to print out a LangChain object
without having any secrets included in raw format in the string representation.

Set up for development

Prior to making any changes in the code:

https://github.com/langchain-ai/langchain/blob/master/.github/CONTRIBUTING.md

Make sure you're able to test, format, lint from langchain/libs/langchain

make test
make format
make lint

Shall you accept

Shall you accept this challenge, please claim one (and only one) of the modules from the list
below as one that you will be working on, and respond to this issue.

Once you've made the required code changes, open a PR and link to this issue.

Acceptance Criteria

  • invoking str or repr on the the object does not show the secret key

Integration test for the code updated to include tests that:

  • confirms the object can be initialized with an API key provided via the initializer
  • confirms the object can be initialized with an API key provided via an env variable

Confirm that it works:

  • either re-run notebook for the given object or else add an appropriate test
    that confirms that the actual secret is used appropriately (i.e.,.get_secret_value())

If your code does not use get_secret_value() somewhere, then it probably contains a bug!

Modules

  • langchain/chat_models/anyscale.py @aidoskanapyanov
  • langchain/chat_models/azure_openai.py @onesolpark
  • langchain/chat_models/azureml_endpoint.py @fyasla
  • langchain/chat_models/baichuan.py
  • langchain/chat_models/everlyai.py @sfreisthler
  • langchain/chat_models/fireworks.py @nepalprabin
  • langchain/chat_models/google_palm.py @faisalt14
  • langchain/chat_models/javelin_ai_gateway.py
  • langchain/chat_models/jinachat.py
  • langchain/chat_models/konko.py
  • langchain/chat_models/litellm.py
  • langchain/chat_models/openai.py @AnasKhan0607
  • langchain/chat_models/tongyi.py
  • langchain/llms/ai21.py
  • langchain/llms/aleph_alpha.py @slangenbach
  • langchain/llms/anthropic.py
  • langchain/llms/anyscale.py @aidoskanapyanov
  • langchain/llms/arcee.py
  • langchain/llms/azureml_endpoint.py
  • langchain/llms/bananadev.py
  • langchain/llms/cerebriumai.py
  • langchain/llms/cohere.py @arunsathiya
  • langchain/llms/edenai.py @kristinspenc
  • langchain/llms/fireworks.py
  • langchain/llms/forefrontai.py
  • langchain/llms/google_palm.py @Harshil-Patel28
  • langchain/llms/gooseai.py
  • langchain/llms/javelin_ai_gateway.py
  • langchain/llms/minimax.py
  • langchain/llms/nlpcloud.py
  • langchain/llms/openai.py @HassanA01
  • langchain/llms/petals.py @akshatvishu
  • langchain/llms/pipelineai.py
  • langchain/llms/predibase.py
  • langchain/llms/stochasticai.py
  • langchain/llms/symblai_nebula.py @praveenv
  • langchain/llms/together.py
  • langchain/llms/tongyi.py
  • langchain/llms/writer.py @ommirzaei
  • langchain/llms/yandex.py

Motivation

Prevent secrets from being printed out when printing the given langchain object.

Your contribution

Please sign up by responding to this issue and including the name of the module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions