Session#
- class scikitplot.cleanprompt.Session(**options)[source]#
A conversation: consistent placeholders, and a vault with a lifetime.
- Parameters:
- **options
Any keyword
encodeaccepts. They apply to every turn.
- Parameters:
options (Any)
Notes
User notes. Use it as a context manager so the values are cleared when the block ends, however it ends:
with session(ner=True) as chat: reply = chat.roundtrip("Summarise this for ada@example.com", send=model)
Across turns the same value keeps the same placeholder, so a model reading the thread sees one consistent participant rather than a new stranger each time.
Developer notes. Continuity is carried by passing the previous turn’s entries into the next
Redactor.redactcall as aseed. The redactor itself stays stateless — that is invariant I4 and the upstream defectCP-003— and the session is the object that deliberately owns the link between two documents.A session is not thread-safe: it is a conversation, and a conversation has one voice. Use one session per thread.
Examples
>>> with session() as chat: ... first = chat.encode("Mail ada@example.com") ... second = chat.encode("Ping ada@example.com again") >>> first, second ('Mail [EMAIL-1]', 'Ping [EMAIL-1] again')
- decode_report(reply)[source]#
Restore
replyand report what was and was not resolved.- Returns:
- RestorationResult
Carries
restored,unknownandunused.
- Parameters:
reply (str)
- property policy: RedactionPolicy#
the policy every turn uses.
- Type:
- report()[source]#
Return what this session has done and what it can and cannot detect.
- Returns:
- dict
turns,entries,labels(placeholder to category, in issue order) anddetection, which is the fulldiagnosereport.
- Return type:
Notes
User notes. Safe to print, log or attach to a ticket: it names placeholders and categories, never values.
Developer notes. This returned the diagnosis alone, which is what the session can detect and says nothing about what it did. On a session object
report()reads as “tell me about this session”, and a caller who wanted the turn count had to reach past the method to.turns. The diagnosis is still here, underdetection; the session’s own state is now the top level.labelsmaps each placeholder to its category and deliberately stops there. The placeholder is already in the text that was sent, so it discloses nothing, while the value it stands for is exactly what this submodule exists to keep out of anything that gets copied elsewhere.
- roundtrip(text, send, *, strict=False)[source]#
Encode, hand to
send, decode the answer.- Parameters:
- textstr
This turn’s prompt.
- sendcallable
Takes the safe text, returns the model’s reply. Any provider.
- strictbool, default=False
Passed to
decode.
- Returns:
- str
The reply with your values restored.
- Raises:
- CleanPromptError
If
senddoes not return a string. Anythingsenditself raises propagates unchanged: it is the caller’s client and the caller’s error.
- Parameters:
- Return type:
Examples
>>> with session() as chat: ... chat.roundtrip( ... "Mail ada@example.com", ... send=lambda safe: "Sent to " + safe.split()[-1], ... ) 'Sent to ada@example.com'
Gallery examples#
Cleanprompt Recipes: CI Gates, Notebooks, Pipelines and Agents