Closed baskaryan closed 1 month ago
@alx13
Yep. Unfortunately it's an issue with underlying library:
Pydantic models need to be constructed in a very specific way to avoid unsupported properties with Schema.
Let me check how model can be constructed.
It's related with: https://github.com/pydantic/pydantic/issues/3896
And this generates a schema without allOf:
from typings import Annotated
from langchain_core.pydantic_v1 import BaseModel, Field
class Node(BaseModel):
id: str
type: str
class Relationship(BaseModel):
source: Node
target: Node = Annotated[Node, "foo"]
Relationship.schema()
It's related with: pydantic/pydantic#3896
And this generates a schema without allOf:
from typings import Annotated from langchain_core.pydantic_v1 import BaseModel, Field class Node(BaseModel): id: str type: str class Relationship(BaseModel): source: Node target: Node = Annotated[Node, "foo"] Relationship.schema()
what schema does that generate?
{
"title": "Relationship",
"type": "object",
"properties": {
"source": {
"title": "Node",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
},
"target": {
"title": "Node",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
}
},
"required": [
"source",
"target"
]
}
so the description is ignored altogether?
Yep you are right, missed that.
And my example was incorrect.
So currently you can use that approach:
class Node(BaseModel):
"""foo"""
id: str
type: str
class Relationship(BaseModel):
source: Node
target: Node
or if class will be used for different fields:
class Node(BaseModel):
id: str
type: str
class NodeTarget(Node):
"""foo"""
class Relationship(BaseModel):
source: Node
target: NodeTarget
which produces:
{
"title": "Relationship",
"type": "object",
"properties": {
"source": {
"title": "Node",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
},
"target": {
"title": "NodeTarget",
"description": "foo",
"type": "object",
"properties": {
"id": {
"title": "Id",
"type": "string"
},
"type": {
"title": "Type",
"type": "string"
}
},
"required": [
"id",
"type"
]
}
},
"required": [
"source",
"target"
]
}
pydantic json schema will include an allOf if a nested object has a description. for example
generates
notice difference between 'source' and 'target'.
When trying to use function-calling, the allOf leads to a protobuf error
using