PlainID LangChain library
Project description
langchain_plainid
PlainID for LangChain. Library which helps you to integrate PlainID with LangChain.
Installation
Based on your environment, you can install the library using pip:
pip install langchain_plainid
Setup with PlainID
Once you have installed the library, you can set up PlainID access.
- Retrieve your PlainID credentials to access the platform - client ID and client secret.
- Find you PlainID base URL. For productoin platform you can use
https://platform-product.us1.plainid.io. Notice URL starts fromplatform-product.
These are 3 parameters you need to use with the library. Note Please don't share your credentials with anyone, don't store them in your code. Use environment variables or secret management tools to store them.
Category filtering
To use category filtering with this library, you need to setup related ruleset in PlainID.
e.g if we are using categories template name, we need to add the following ruleset:
# METADATA
# custom:
# plainid:
# kind: Ruleset
# name: All
ruleset(asset, identity, requestParams, action) if {
asset.template == "categories"
}
and setup what categories are available in PlainID through asset types.
e.g. add the following assets: contract, HR.
Now it's time to use category filtering in your LangChain application.
from langchain_plainid import PlainIDCategorizer, PlainIDPermissionsProvider
permissions_provider = PlainIDPermissionsProvider(
client_id="your_client_id",
client_secret="your_client_secret",
base_url="https://platform-product.us1.plainid.io",
plainid_categories_resource_type="categories")
plainid_categorizer = PlainIDCategorizer(classifier_provider=<classifier>,permissions_provider=permissions_provider)
chain = plainid_categorizer
query = "I'd like to know the weather forecast for today"
result = chain.invoke(f"{query}") # push your prompt to the chain
Categorizer will connect to PlainID and retrieve the list of categories available in your PlainID account.
Then it will classify your prompt with provided classifier and pass your query to the next chain element or break execution with ValueError exception.
Category classifiers
We provide 2 classifiers out of the box:
LLMCategoryClassifierProvider
This classifier uses LLM to classify your prompt. It uses langchain LLMs to classify your prompt. You can configure it with any LLM you want.
from langchain_plainid import LLMCategoryClassifierProvider
llm_classifier = LLMCategoryClassifierProvider(llm=OllamaLLM(model="llama2"))
Use it with caution, quality of classification depends on the LLM you are using. Some base models could return bad or even wrong results, so use it with big models (OpenAI, Anthropic, etc.) or with models which are trained for classification tasks.
ZeroShotCategoryClassifierProvider
This used LLM model which suits best for classification tasks. During the work it will download the model from HuggingFace and use it to classify your prompt.
from langchain_plainid import ZeroShotCategoryClassifierProvider
zeroshot_classifier = ZeroShotCategoryClassifierProvider()
Use it if you want better classification results, but also have free space on your disk, and can wait for the model to be downloaded.
Anonymizer
To use anonymizer with this library, you need to setup related ruleset in PlainID.
e.g if we are using entities template name, we need to add the following ruleset:
# METADATA
# custom:
# plainid:
# kind: Ruleset
# name: PERSON
ruleset(asset, identity, requestParams, action) if {
asset.template == "entities"
asset["path"] == "PERSON"
action.id in ["MASK"]
}
We support 2 actions: MASK and ENCRYPT. You can use them to mask or encrypt your data.
Data is always masked with *** symbols.
The list of possible anonymization sources are based on PII entities. We are using presidio library from Microsoft to detect PII entities in your text. You can find the list of supported entities here
Anonymizer will connect to PlainID and retrieve the list of categories available in your PlainID account.
Then it will classify your text and anonymize it. Processed text will be passed the next chain element or break execution with ValueError exception. Exception will be raised if there are some problems, or misalignment in your PlainID ruleset.
Power of creating your chains with PlainID's internal category filtering and anonymization
As a result you can add something like this to your processing chain:
chain = plainid_categorizer | llm | vector_store | anonymizer | outpur_parser
This will allow you to filter your data based on categories and anonymize it before passing to the next chain element. You can use any chain element you want, and it will work with PlainID's internal category filtering and anonymization.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_plainid-0.1.4.tar.gz.
File metadata
- Download URL: langchain_plainid-0.1.4.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
916852e0e2f9d2c78b3aae18012ced4c279270a3020d1375f1a58f456d4adea9
|
|
| MD5 |
32fedb06f0683e3f2510ed6e345b5c93
|
|
| BLAKE2b-256 |
1826b4ae8717b918604588518211e90b653aeba3651601a6bfb9145e542c0e9b
|
File details
Details for the file langchain_plainid-0.1.4-py3-none-any.whl.
File metadata
- Download URL: langchain_plainid-0.1.4-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43a8a87542af75bfb82e94d9dfe7a8379a7cfd2d87cf660110c1deea23af65cd
|
|
| MD5 |
94e0c7aac2f08832c503e3e744c42849
|
|
| BLAKE2b-256 |
eacf20aed6f8c8d6a2677cd03725507803df2753d8ae7bae0376468a5f74d4ae
|