Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to specify a schema where an object can be any key-value combination #54

Open
simaotwx opened this issue Apr 24, 2024 · 0 comments
Open

Comments

@simaotwx
Copy link

I want the LLM to generate a JSON like this

{
  "name": "John Doe",
  "info": {
    "age": "41",
    "tennis_club": "Detroit Club",
    "wife": "Jan Doe",
  }
}

The info is not always the same. Some people might not have a wife so the property would be omitted.
In theory, there could be thousands of combinations in the "info".

If I specify a schema like this:

{
    "type": "object",
    "properties": {
        "name": { "type": "string" },
        "info": {
            "type": "object"
        }
    }
}

It would error with:

  File "venv/lib/python3.11/site-packages/jsonformer/main.py", line 185, in generate_value
    return self.generate_object(schema["properties"], new_obj)
                                ~~~~~~^^^^^^^^^^^^^^
KeyError: 'properties'

So "properties" is required.

The only way I currently see to solve this is to use an array with objects of format {"key": "...", "value": "..."}

So the schema would look like:

{
    "type": "object",
    "properties": {
        "name": { "type": "string" },
        "info": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "key": { "type": "string" },
                    "value": { "type": "string" }
               }
           }
        }
    }
}

But I'd rather avoid this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant