POML Integrations¶
Estimated time to read: 1 minute
poml.integration.agentops
¶
log_poml_call(name, prompt, context, stylesheet, result)
¶
Log the entire poml call to agentops.
Source code in python/poml/integration/agentops.py
poml.integration.langchain
¶
LangchainPomlTemplate
¶
Bases: PromptTemplate
A LangChain-compatible prompt template that uses POML (Prompt Markup Language) for formatting.
This class extends LangChain's PromptTemplate to support POML markup, enabling rich prompt formatting with speaker modes and structured content. It can load templates from files or strings and format them into either ChatPromptValue or StringPromptValue objects.
Attributes:
Name | Type | Description |
---|---|---|
template_file |
Union[str, Path, None]
|
Path to the POML template file, if loaded from file. |
speaker_mode |
bool
|
Whether to format output as chat messages (True) or plain text (False). Defaults to True. |
Examples:
Create from a template string:
>>> template = LangchainPomlTemplate.from_template(
... "Hello {{name}}!", speaker_mode=True
... )
>>> result = template.format(name="Alice")
Load from a POML file:
>>> template = LangchainPomlTemplate.from_file(
... "path/to/template.poml", speaker_mode=False
... )
>>> result = template.format(user_input="What is AI?")
Note
- In speaker_mode=True, returns ChatPromptValue with structured messages
- In speaker_mode=False, returns StringPromptValue with plain text
- The from_examples() method is not supported and will raise NotImplementedError
Source code in python/poml/integration/langchain.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
poml.integration.mlflow
¶
log_poml_call(name, prompt, context, stylesheet, result)
¶
Log the entire poml call to mlflow.
Source code in python/poml/integration/mlflow.py
poml.integration.pydantic
¶
NotGiven
¶
A sentinel singleton class used to distinguish omitted keyword arguments from those passed in with the value None (which may have different behavior).
Source code in python/poml/integration/pydantic.py
is_dataclass_like_type(typ)
¶
to_strict_json_schema(model)
¶
Convert a Pydantic model to a strict JSON schema suitable for OpenAI function calling and response format.
This function takes a Pydantic BaseModel class or TypeAdapter and converts it to a JSON schema
that conforms to the strict schema requirements for OpenAI's function calling API. The resulting
schema ensures all objects have additionalProperties: false
and all properties are required.
Most of the implementation is adapted from OpenAI Python SDK.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
type[BaseModel] | TypeAdapter[Any]
|
A Pydantic BaseModel class or TypeAdapter instance to convert to JSON schema |
required |
Returns:
Type | Description |
---|---|
dict[str, Any]
|
A dictionary representing the strict JSON schema |
Raises:
Type | Description |
---|---|
TypeError
|
If the model is not a BaseModel type and Pydantic v2 is not available, or if a non-BaseModel type is used with Pydantic v1 |
Example
from pydantic import BaseModel, Field
from poml.integration.pydantic import to_strict_json_schema
class Query(BaseModel):
name: str = Field(description="Query name")
limit: int = Field(description="Result limit", default=10)
schema = to_strict_json_schema(Query)
# Returns a strict JSON schema with additionalProperties: false
Source code in python/poml/integration/pydantic.py
poml.integration.weave
¶
log_poml_call(name, prompt, context, stylesheet, result)
¶
Log the entire poml call to weave.