<@U04S8PLJWMT> how can I get the max of a string a...
# ask-ai
j
@kapa.ai how can I get the max of a string and an integer using jinja?
k
In Jinja (as used in Airbyte config-based connectors), the max macro or filter is designed to return the largest object from an iterable or from two or more arguments. However, the comparison must be between compatible types—typically all numbers or all strings. Comparing a string and an integer directly (e.g., {{ max("5", 3) }}) will result in a TypeError, because Python (and thus Jinja) does not support comparison between strings and integers. To safely get the max of a string and an integer, you should first convert the string to an integer using the int filter, like this:
Copy code
{{ max("5"|int, 3) }}
This will output 5, as both arguments are now integers and can be compared safely. The Airbyte documentation confirms the use of max for iterables or multiple arguments, but does not specify handling mixed types. Therefore, explicit type conversion is necessary to avoid errors, as shown above. If you attempt to compare a string and an integer without conversion, you will encounter a TypeError, similar to the one described in the Airbyte GitHub issue for the YouTube Analytics connector, where a string and an integer were compared and caused a failure ([source-youtube-analytics] - TypeError: '>' not supported between instances of 'str' and 'int'). References: - [YAML Reference: max macro](https://docs.airbyte.com/platform/next/connector-development/config-based/understanding-the-yaml-file/reference#/macros/max) - [Jinja2 filters and type conversion](https://docs.airbyte.com/platform/next/connector-development/config-based/advanced-topics/oauth#commonly-used-jinja2-in-variables-interpolation-methods-available-the-list-is-not-exhaustive) - [GitHub Issue: TypeError in source-youtube-analytics](https://github.com/airbytehq/airbyte/issues/61319)
j
@kapa.ai
int
is not an available jinja expression
k
A message from kapa.ai
Based on the available Airbyte documentation, the Jinja2 filters and macros supported in Airbyte include a variety of type conversion and utility functions. However, there is no mention of an int filter or macro being available for type conversion in Jinja expressions within Airbyte config-based connectors. The documented filters include string, base64encode, base64decode, hash, and regex_search, but not int or similar numeric type conversion filters [Interpolation filters](https://docs.airbyte.com/platform/1.7/connector-development/config-based/understanding-the-yaml-file/reference#filters). Therefore, you cannot directly convert a string to an integer using int in Airbyte’s Jinja context. As a result, you cannot safely use max to compare a string and an integer in Jinja within Airbyte. Attempting to do so will likely result in a type error, as described in the referenced GitHub issue for the YouTube Analytics connector, where a TypeError occurred when comparing a string and an integer [source-youtube-analytics TypeError](https://github.com/airbytehq/airbyte/issues/61319). Summary: You cannot use int as a Jinja filter in Airbyte config-based connectors, so you cannot directly get the max of a string and an integer in this context. The knowledge sources do not provide a workaround for this limitation.