Messages
Message types and semantics used across invocations.
#Messages
The public message helpers live in maivn.messages and convert to the owned maivn_contracts.messages.Message wire contract.
Redaction aids, not compliance.phi_modeandHIPAA_SAFE_HARBOR_CATEGORIESare redaction aids. Using them does not make a deployment compliant with health-privacy law, and the hosted Service does not accept protected health information without a separate signed agreement; see the Acceptable Use Policy. mAIvn holds no SOC 2, HIPAA, ISO 27001, or FedRAMP certification, and cannot guarantee that every private value is detected. These controls do not replace required audits and organizational safeguards.
#Imports
from maivn.messages import (
AIMessage,
BaseMessage,
HumanMessage,
PrivateData,
RedactedMessage,
SystemMessage,
ToolMessage,
to_contract_messages,
)
from maivn_contracts.messages import Attachment, ContentBlock, Message, RedactionConfig#Convenience messages
HumanMessage, AIMessage, SystemMessage, and ToolMessage are frozen Pydantic models with fixed roles. Their shared shape is:
content: str | list[ContentBlock]
role: MessageRole
message_id: str = generated
attachments: Sequence[Attachment | Mapping[str, object]] | None = None
artifact_refs: tuple[ArtifactRef, ...] | None = None
redaction: RedactionConfig | None = None
metadata: dict[str, MetadataValue] | None = None
ts: str = generated UTC timestampfrom maivn.messages import HumanMessage, SystemMessage
messages = [
SystemMessage(content='Answer concisely.'),
HumanMessage(content='Summarize this ticket.'),
]
response = agent.invoke(messages)artifact_refs carries references to generated files, at most 32 per message. See Artifacts. BaseMessage.to_contract() returns a validated wire Message. to_contract_messages(...) accepts one string/message or a sequence and normalizes everything to list[Message].
#Chat-style dictionaries
New in maivn 3.0.0. Earlier releases refuse a dictionary with a list of content validation errors.
Anywhere a message is accepted, you can pass a dictionary with a role and a content, the shape most chat APIs use. The role picks the message class: user is a HumanMessage, assistant an AIMessage, system a SystemMessage and tool a ToolMessage. Any other key must be a field of that class, such as attachments or metadata.
response = agent.invoke(
[
{'role': 'system', 'content': 'You are a careful support analyst.'},
{'role': 'user', 'content': 'Summarize the order status.'},
]
)A dictionary with no role, or a role outside those four, raises a TypeError that names the accepted roles.
#Attachments
Message constructors accept contract Attachment objects or dictionaries. A storage-backed dictionary supplies storage_ref, content_hash, filename, MIME type, and size. An inline dictionary supplies one of inline_base64, content_base64, content_bytes, or text_content. The SDK derives base64, size, and SHA-256 where needed.
from maivn.messages import HumanMessage
message = HumanMessage(
content='Use the attached runbook.',
attachments=[
{
'filename': 'runbook.txt',
'mime_type': 'text/plain',
'text_content': 'Rollback if canary checks fail.',
}
],
)Local file-path loading is not a message-constructor feature. Read an authorized file yourself and pass bytes/base64, or register it through the SDK resource APIs.
#PrivateData and RedactedMessage
PrivateData is a frozen descriptor with required value: object plus optional name, pii_type, label, description, and format fields.
RedactedMessage accepts text or content blocks, optional known PII values, a whitelist, attachments, metadata, message ID, and timestamp:
from maivn import PIIWhitelist, PIIWhitelistEntry
from maivn.messages import PrivateData, RedactedMessage
whitelist = PIIWhitelist(
entries=(
PIIWhitelistEntry(
value='hello@maivn.io',
justification='Published support address.',
),
)
)
message = RedactedMessage(
content='Contact Maria at maria@example.com or hello@maivn.io.',
known_pii_values=[PrivateData(value='Maria', name='customer_name')],
pii_whitelist=whitelist,
)Each PIIWhitelistEntry requires exactly one of entity_type, pattern, or value, plus a justification of 8 to 512 characters. A literal value must be at least 3 characters. phi_mode=True rejects category-wide entries for exported HIPAA_SAFE_HARBOR_CATEGORIES. It is a technical category guard, not a compliance guarantee.
RedactedMessage.to_contract() returns a user-role Message with a RedactionConfig carrying the known values and whitelist.
Text attachments on a RedactedMessage are redacted with the message. Photographs and PDFs are covered by reading the page, with the same whitelist. Video and audio are refused. See Photographs and Scanned PDFs.
See Private Data for execution-time injection and control limitations.