Hitting a wall, JSON Template won't pull dynamic values

I have the below template; however, when I try to query dynamic values from the same table, they aren’t pulling. I’ve checked the docs and videos but still no luck. Thoughts?

TEMPLATE:

{
“model”: “claude-3-opus-20240229”,
“max_tokens”: 1000,
“system”: [
{
“type”: “text”,
“text”: “prompt.”
}
],
“messages”: [
{
“role”: “user”,
“content”: "prompt data.

Age: $age
Postal Code: $postal_code
Gender: $gender
Traffic Source: $traffic_source

prompt"
}
]
}

Maybe the new line characters in your content variable is making it an invalid JSON.

What are you trying to do though? You’re constructing what looks like a body of an API call, but now you want to query from that body?

1 Like

Gave that a try as well, no luck unfortunately .

I wonder if because I’m passing a json structure within a quoted json object, that I may need to dynamically place a nested JSON?

image

in this simple test yes it does work, but its like any time I put in the $ it basically breaks it. Is it because I’m trying to pass dynamic data within the “” for the original JSON message?

I took those out just in case and still the same issue.

I’m trying to pass dynamic content into the text of the prompt I’m sending to Anthropic’s API. I’m 99% certain its because I put the data in “”, so then when I try to pass dynamic variables into the literal text, it wont make it dynamic, but unsure how you would pass dynamic content within a json request unless I remove the “”?

The issue is if I remove the “” it breaks the json template

Ah!.. you are using the JSON Template column, not the original Template, sorry for my confusion.

Let’s test with this small example (template) to validate syntax and variables:

{
  "model": "claude-3-opus-20240229",
  "max_tokens": 1000,
  "system": [
    {
      "type": "text",
      "text": "prompt."
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "prompt data.",
      "Age": $age,
      "Postal Code": $postal_code,
      "Gender": "$gender",
      "Traffic Source": "$traffic_source"
    }
  ]
}

Let me know if it worked

Simplified to:

{
“model”: “claude-3-opus-20240229”,
“max_tokens”: 1000,
“system”: [
{
“type”: “text”,
“text”: “prompt.”
}
],
“messages”: [
{
“Gender”: “$gender”
}
]
}


image

{
  "model": "claude-3-opus-20240229",
  "max_tokens": 1000,
  "system": [
    {
      "type": "text",
      "text": "text input"
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "content"


    }
  ]
}

Here is a simplified version

Side note: when posting JSON you can use triple-backticks and it will format nicely. I fixed that last one for you.

1 Like

Can you show me what you mean? as a note I tried to pass multiple messages to Anthropic’s API but it doesn’t allow it unfortuantely.

If you edit your previous post you’ll see what I mean.

1 Like

json

{
“model”: “claude-3-opus-20240229”,
“max_tokens”: 1000,
“system”: [
{
“type”: “text”,
“text”: “prompt.”
}
],
“messages”: [
{
“role”: “user”,
“content”: "prompt data.

Age: $age
Postal Code: $postal_code
Gender: $gender
Traffic Source: $traffic_source

prompt"
}
]
}

Looks like you are using smart quotes. You need to use back ticks, and put them on a separate line, like below:

The problem if you just paste the JSON without using the back ticks is that all the double quotes get converted to smart quotes, and it breaks the JSON. This makes it harder for anyone that is trying to help you.

Jordan,

Use this option to paste your code in order to avoid some invalid characters like your “ ”.
You must use these instead: " "
Did you see the difference?

image

Thank you!! Here is the current simplified version that I have but still cant get dynamic content in

{
“model”: “claude-3-opus-20240229”,
“max_tokens”: 1000,
“system”: “You are an AI assistant tasked with classifying users based on provided information.”,
“messages”: [
{
“role”: “user”,
“content”: “Tell me how you would classify this user in 10 words or less as a person Gender:$gender”
}
]
}


{
  "model": "claude-3-opus-20240229",
  "max_tokens": 1000,
  "system": "You are an AI assistant tasked with classifying users based on provided information.",
  "messages": [
    {
      "role": "user",
      "content": "Tell me how you would classify this user in 10 words or less as a person Gender:$gender" 
    }
  ]
}

Found the solution!!

  1. create the json as a normal text Template column
  2. have a dynamic reference in a new column for JSON Template of the Template column above
1 Like
{
  "model": "claude-3-opus-20240229",
  "max_tokens": 1000,
  "system": [
    {
      "type": $text,
      "text": $textInput
    }
  ],
  "messages": [
    {
      "role": $role,
      "content": $content
    }
  ]
}

This works normally for me.

Also, the $gender binder here can’t work if you are trying to have that inside double quotes. It seems like you can only tie values/objects directly to a variable, not inside another value like that. If you want to do that, using a template column before that, just for that value, is the way to go.

The issue here is passing a static command + dynamic content

Yeah, I mean if you want a dynamic value inside a variable, using the template column beforehand makes sense.